JavaScript 継承の型

JavaScript の継承、毎回どう書くんだったかな、とぐぐることになるので、流用元となる型を記事にしておきます。

function Base(type){
	this.type = type;
}
Base.prototype.method01 = function(msg){
	if(!msg){
		msg = 'デフォルト';
	}
	console.log(msg + '!');
};
function Hoge(prop1){
	Base.call(this, "Hoge");
	this.prop1 = prop1;
}
// 古いブラウザに対応する場合?
// Hoge.prototype = new Base();
Hoge.prototype = Object.create(Base.prototype);
Hoge.prototype.constructor = Hoge;
Hoge.prototype.method01 = function(){
	// Base側の処理を継承する場合
	Base.prototype.method01.call(this,'ホゲでござる');
	// 独自処理
	console.log('Hoge独自');
};
var hoge = new Hoge('プロパティ1');
hoge.method01();// ホゲでござる!
console.log(hoge instanceof Base);// true
console.log(hoge instanceof Hoge);// true
console.log(Base.prototype.isPrototypeOf(hoge));// true
console.log(Hoge.prototype.isPrototypeOf(hoge));// true