Created
February 17, 2015 05:45
-
-
Save tacamy/cf0f239ddbff9e0e28ae to your computer and use it in GitHub Desktop.
Object.createを使わないクラスの継承
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 ObjectCreate(o) { | |
function F() {} | |
F.prototype = o; | |
return new F(); | |
} | |
function Parent(text) { | |
console.log('called parent'); | |
this.text = text || 'default text'; | |
} | |
function Child(text) { | |
Parent.call(this, text); | |
} | |
Child.prototype = ObjectCreate(Parent.prototype); | |
var c = new Child('child text!'); | |
console.log(c.text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment