How can I check instanceof without the proto chain in javascript?
问题 How can I check instanceof without the proto chain in javascript? var EventEmitter = require('events').EventEmitter; var Foo = function(){ }; Foo.prototype = EventEmitter.prototype; var Bar = function(){ }; Bar.prototype = EventEmitter.prototype; var f = new Foo(); var b = new Bar(); f instanceof Foo; //returns true b instanceof Bar; //returns true f instanceof Bar; //returns true b instanceof Foo; //returns true Essentially, I want those last two lines to return false. How do I do that? 回答1: