Created
October 27, 2014 18:44
-
-
Save joshvfleming/0539f00dd12392483596 to your computer and use it in GitHub Desktop.
Nashorn "this" binding bug reduction
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
// -- BEGIN CODE -- | |
function subclass(parentConstructor, proto) { | |
function C() { | |
parentConstructor.call(this); | |
} | |
C.prototype = Object.create(parentConstructor.prototype); | |
for (var prop in proto) { | |
if (proto.hasOwnProperty(prop)) { | |
C.prototype[prop] = proto[prop]; | |
} | |
} | |
return C; | |
} | |
var Parent = function() { | |
this.init(); | |
}; | |
Parent.prototype = { | |
init: null | |
} | |
var Child1 = subclass(Parent, { | |
prop1: 1, | |
init: function() { | |
print('!!! child 1'); | |
} | |
}); | |
var Child2 = subclass(Parent, { | |
init: function() { | |
print('!!! child 2'); | |
} | |
}); | |
new Child1(); | |
new Child2(); | |
// -- END CODE -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment