Last active
January 3, 2016 00:19
-
-
Save cyjake/8381942 to your computer and use it in GitHub Desktop.
Creating sub classes with prototype assigning directly will confuse instanceof operator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util') | |
function Class() {} | |
function SubClass() {} | |
function WrongSubClass() {} | |
util.inherits(SubClass, Class) | |
util.inherits(WrongSubClass, Class) | |
WrongSubClass.prototype = Class.prototype | |
var foo = new SubClass() | |
console.log(foo instanceof WrongSubClass) // ==> logs true, should be false obviously |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment