-
-
Save jimmycuadra/3659753 to your computer and use it in GitHub Desktop.
Beget question (prototypal inheritance)
This file contains hidden or 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
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