JS-Interpreter
JS-Interpreter copied to clipboard
new and typeof have special behaviour on bound functions
The following code should return [true, true, true true] but in fact returns [true, false, false, true]:
"use strict";
function F() { /* does nothing */ };
F.prototype = {foo: "F"}
var G = F.bind(42);
G.prototype = {foo: "G"}
var f = new F();
var g = new G();
[f instanceof F, f instanceof G, g instanceof F, g instanceof G]
Related, the bind polyfill from Mozilla is also unable to handle this:
new (Function.prototype.bind.apply(Date, [null, 100, 200, 300, 400]));
Which should equal:
new Date(100, 200, 300, 400)