Consider the following two snippets:
obj = {}; // can be [], Number(), eg. but not Function()
obj[Symbol.hasInstance] = () => console.log('89');
({}) instanceof obj;
and
obj = function() {}; // new Function() too
obj[Symbol.hasInstance] = () => console.log('89');
({}) instanceof obj;
Both should log '89' but only in the first snippet '89' is logged.
In Chrome 52, first logs 89, second logs nothing.
In node v6.3.1 first results in TypeError: Expecting a function in instanceof check, but got #<Object>
, while second logs nothing.
Is this a bug? What is the intended behaviour? On MDN there is nothing explaining this.
Aucun commentaire:
Enregistrer un commentaire