Skip to content

Instantly share code, notes, and snippets.

@tacamy
Created February 17, 2015 05:45
Show Gist options
  • Save tacamy/cf0f239ddbff9e0e28ae to your computer and use it in GitHub Desktop.
Save tacamy/cf0f239ddbff9e0e28ae to your computer and use it in GitHub Desktop.
Object.createを使わないクラスの継承
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