function F() {
return function() {
return {};
}
}
var f = new F();
f instanceof F; // returns false
As far as I understand, if I w
In you your example F is not a constructor it is a function that returns an anonymous constructor which you then call new upon. instanceof works by looking at the prototype chain, so your code doesn't work because you haven't setup up the prototypes correctly.
This page has a good explain of JavaScript Constructors and how to subsclass.
Take a look at the following code and see if it helps.
function F() {
this.whoami = 'F';
this.whatami = 'F';
}
function Sub() {
this.whoami = 'G';
}
Sub.prototype = new F();
function G() {
return new Sub;
}
var f = new G();
console.log(f instanceof F); // returns false
console.log(f.whoami);
console.log(f.whatami);