function F() {
return function() {
return {};
}
}
var f = new F();
f instanceof F; // returns false
As far as I understand, if I w
To anyone coming across this today, with ES6/2015 there's new syntax you can use to avoid the deprecated __proto__ property; Object.setPrototypeOf. Note that MDN warns that this is a slow/expensive operation.
function F() {
const f = function() {
return {};
}
Object.setPrototypeOf(f, F.prototype);
return f;
}
var f = new F();
f instanceof F; // returns true
f(); // returns {}
Note also that it gets a little weird if you want to initialize values in the constructor. You need to set them as props on the function you will return, but later additions to the prototype will reference them as 'this'. e.g.
function F() {
const f = function() {
return {};
}
f.favoriteBand = 'The Books';
Object.setPrototypeOf(f, F.prototype);
return f;
}
F.prototype.getFavoriteBand = function(){ return this.favoriteBand; }
var f = new F();
f.getFavoriteBand() // returns 'The Books'