给JavaScript的单个对象定义属性和属性的元数据

</div><div data-lake-id="42b26386b37abdd28d1ecaa28fb0b00a">var person = {</div><div data-lake-id="394acf9ea87b5f85b3ae1cb2548068b5">name:"dwqs",</div><div data-lake-id="9b88026f68d6d8b6fdaf6e3e8769634a">age:20,</div><div data-lake-id="719c86d88cc5ea955f344f7d30513ace">interesting:"coding",</div><div data-lake-id="0648f0d1e892939f1ef29e160c630416">blog: "www.sap.com"</div><div data-lake-id="d4e340e91cc3c99fb5444bd375224abc">};</div><div data-lake-id="d99d44a86aef0d14aa26603058aa548b">//定义sex属性,writable是false,所以不能修改</div><div data-lake-id="aff7910ce986d5d33dd6d934c89d50f1">Object.defineProperty(person,"sex",{</div><div data-lake-id="534d63adf737e0bcd34534157468f571">writable:false,</div><div data-lake-id="a14cba907b846bd981dc67673397d82c">value:"male"</div><div data-lake-id="b88147d76132d153f22ee3a546f2de3b">});</div><div data-lake-id="3de76897f280f94713490921b0994a61">console.log(person.sex); //male</div><div data-lake-id="d426e34b062e3adae16043fee1cc7f81">//在严格模式下出错,非严格模式赋值被忽略</div><div data-lake-id="5a26683c5c4afca6222ba45c6263f472">person.sex = "Jerry";</div><div data-lake-id="4922250e772cafb449da421f5b8eab7f">console.log(person.sex);  </div><div data-lake-id="71bccb8458b43b4fc853a0f2d2218b93">var prop = Object.getOwnPropertyDescriptor(person,"sex");</div><div data-lake-id="5738fc69d20f3095c5c9c4505ddd0707">debugger;</div><div data-lake-id="3e8523f5efae5025330630ab714a153e">


上一篇:Oracle 数据库发生等待事件:enq: TX - row lock contention ,排查思路


下一篇:MEF 插件式开发之 WPF 初体验