Consider the simple code below:
function C1() {
let x=5;
}
var c1=new C1;
alert(c1 instanceof C1); // returns true
function C2() {
let x=5;
return {
getx() { return x; }
}
}
var c2=new C2;
alert(c2 instanceof C2); // returns false ! why ??
Questions:
why is c2 not an instance of C2 ?
how can I have a constructor returning an object (ie C2) and still have new returning an instance of that constructor WITHOUT changing C2 ?