Various variants of checking for constructor
JavaScript
function IsInstance() {
if (! (this instanceof IsInstance)) throw "No way!";
document.body.innerHTML += 1;
}
var A = IsInstance;
function IsInstance() {};
var a = new A;
// - - -
function Constructor() {
if (this.constructor != Constructor) throw "No way!";
document.body.innerHTML += 2;
}
var C = Constructor;
function Constructor() {}
var c = new C;
// - - -
function NamedFunction() {
if (this.constructor.name !== 'NamedFunction') throw "No way!";
document.body.innerHTML += 3;
}
//NamedFunction.name = "Good bye";
//var nf = new NamedFunction();
var x = function NamedFunction () {};
nf = new x;
NamedFunction.call(nf);