Skip to content

Instantly share code, notes, and snippets.

@jimmycuadra
Forked from ClayShentrup/beget.js
Created September 6, 2012 19:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmycuadra/3659753 to your computer and use it in GitHub Desktop.
Save jimmycuadra/3659753 to your computer and use it in GitHub Desktop.
Beget question (prototypal inheritance)
function beget(parent, child) {
// Add code here to make test() return true.
}
function test(){
var c;
function Parent() {
throw 'exception';
}
Parent.prototype.code = Math.random();
function Child() {}
beget(Parent, Child);
delete Child.prototype.code;
c = new Child;
return c.code === Parent.prototype.code &&
Child.prototype !== Parent.prototype &&
c.constructor === Child;
}
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment