JavaScript オブジェクト 新しいページはコチラ
提供: yonewiki
(→.getPrototypeOf 関数) |
(→.setPrototypeOf 関数) |
||
1,353行: | 1,353行: | ||
サンプル | サンプル | ||
<syntaxhighlight lang="javascript" line start="1"> | <syntaxhighlight lang="javascript" line start="1"> | ||
+ | <HTML> | ||
+ | <HEAD> | ||
+ | <TITLE>JavaScript getPrototypeOf</TITLE> | ||
+ | </HEAD> | ||
+ | <BODY> | ||
+ | JavaScript getPrototypeOf<br /> | ||
+ | <SCRIPT Language="JavaScript"> | ||
+ | <!-- | ||
+ | var obj = { | ||
+ | value:"data1", | ||
+ | writable:true, | ||
+ | enumerable:true | ||
+ | }; | ||
+ | function objFunc(){ | ||
+ | this.nValue1 = 100; | ||
+ | this.nValue2 = 200; | ||
+ | } | ||
+ | |||
+ | var objCreate1 = new objFunc(); | ||
+ | |||
+ | var prototypeCreate1 = Object.getPrototypeOf(objCreate1); | ||
+ | |||
+ | document.write("■Object.getPrototypeOf(objCreate1) vs objCreate1<BR />"); | ||
+ | document.write(prototypeCreate1.isPrototypeOf(objCreate1), "<BR />"); | ||
+ | |||
+ | Object.setPrototypeOf(obj,objCreate1); | ||
+ | |||
+ | document.write("■obj←objCreate1後 Create1 prototype vs obj prototype<BR />"); | ||
+ | document.write(prototypeCreate1.isPrototypeOf(obj), "<BR />"); | ||
+ | |||
+ | var prototypeObj = Object.getPrototypeOf(obj); | ||
+ | |||
+ | document.write("■objCreate1 prototype vs obj prototype<BR />"); | ||
+ | document.write(prototypeCreate1.isPrototypeOf(obj), "<BR />"); | ||
+ | document.write("■obj prototype vs obj prototype<BR />"); | ||
+ | document.write(prototypeObj.isPrototypeOf(obj), "<BR />"); | ||
+ | |||
+ | document.write("■obj key値,property値<BR />"); | ||
+ | for(var property in obj){ | ||
+ | document.write(property, ",",obj[property], "<BR />"); | ||
+ | } | ||
+ | --> | ||
+ | </SCRIPT> | ||
+ | </BODY> | ||
+ | </HTML> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Media:JavaScript Object setPrototypeOf.html|実行結果サンプル]] | [[Media:JavaScript Object setPrototypeOf.html|実行結果サンプル]] | ||
− | |||
== .freeze 関数 == | == .freeze 関数 == |