Skip to content

Instantly share code, notes, and snippets.

@joshvfleming
Created October 27, 2014 18:44
Show Gist options
  • Save joshvfleming/0539f00dd12392483596 to your computer and use it in GitHub Desktop.
Save joshvfleming/0539f00dd12392483596 to your computer and use it in GitHub Desktop.
Nashorn "this" binding bug reduction
// -- 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