Skip to content

Instantly share code, notes, and snippets.

@kawabataryo
Created November 8, 2014 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawabataryo/2c213e8a367563f3d53e to your computer and use it in GitHub Desktop.
Save kawabataryo/2c213e8a367563f3d53e to your computer and use it in GitHub Desktop.
クラス継承に関するメモ
//inherits
function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
//A
function A(n){
this.n = n;
this.n10 = n*10;
}
A.prototype.a_method = function(){
return this.n + this.n10;
}
//B
function B(n){
A.call(this,n);
}
inherits(B,A);
//init
var b = new B(1);
b.a_method(); //11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment