JS-Interpreter icon indicating copy to clipboard operation
JS-Interpreter copied to clipboard

new and typeof have special behaviour on bound functions

Open cpcallen opened this issue 8 years ago • 1 comments

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]

cpcallen avatar May 02 '17 21:05 cpcallen

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)

NeilFraser avatar May 02 '17 21:05 NeilFraser