<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script> var proto={"name":"objcreate"}//原型对象属性 var objAge=23 var objprop={ age:{ // value:23, // writable:true, value writable这两个属性不可以和get set 同时使用 enumerable:true, // for k in obj Object.keys(obj) 不管true还是false 原型proto都可以in keys objprop的属性只有true才可以 configurable:true, //属性控制 更改 get(){ return objAge }, set(val){ console.log(val) objAge=val } } } var obj=Object.create(proto,objprop) console.log(obj) console.log(obj.name,obj.age) obj.age=33 console.log(obj.age) for (var k in obj){ console.log(k,obj[k]) } console.log(Object.keys(obj)) //objprop是obj对象整个配置 Object.defineProperty(obj,age,{value:''})是obj对象一个属性的配置 </script> </body> </html>
标签:console,log,create,Object,var,defineProperty,obj,true From: https://www.cnblogs.com/howhy/p/17825964.html