JavaScript prototypeプロパティ

String 对象参考手册JavaScript String オブジェクト


定義と使用方法

prototype プロパティを使用すると、オブジェクトにプロパティとメソッドを追加できます。

注意:Prototype はグローバルプロパティであり、すべての JavaScript オブジェクトに適用されます。

構文

object.prototype.name=value


ブラウザサポート

Internet ExplorerFirefoxOperaGoogle ChromeSafari

すべての主要ブラウザが prototype プロパティをサポートしています。


例

例

prototype プロパティを使用してオブジェクトにプロパティを追加する:

function employee(name,jobtitle,born){ this.name=name; this.jobtitle=jobtitle; this.born=born; } var fred=new employee("Fred Flintstone","Caveman",1970); employee.prototype.salary=null; fred.salary=20000; document.write(fred.salary);

上記の例の出力結果:

20000

試してみる »


String 对象参考手册JavaScript String オブジェクト

その他の拡張