赤いきつねの技術メモブログ

主に技術メモを残す予定です。

プロトタイプ定義はオブジェクトリテラルで

こう書くことで可読性が上がるし、オブジェクト名の変更にも強くなるんだ!

下記のプロトタイプ定義の記述方法をオブジェクトのリテラル表記といいます。

var a = function(){document.writeln("aaa");}

a.prototype = { outputAA : function(){return document.writeln('AA');},
		    outputBB : function(){return document.writeln('BB');}};

var c = new a();
document.writeln(c.outputAA());
document.writeln(c.outputBB());