JavaScript 反射和属性赋值!
程序员文章站
2022-04-16 21:34:17
结果: ......
function antzone(){ this.webname="蚂蚁部落"; this.age=6; } antzone.prototype={ address:"青岛市南区" }
var auth = { add:false, list:false, export:false, import:false, search:false }; console.log(object.keys(auth));
var auth1 = ["add","list","search"]; let antzone=new antzone(); console.log(object.getownpropertynames(antzone));
var names = object.getownpropertynames(auth); console.log(names);
if(auth1.length > 0){ for(var i=0;i<names.length;i++){ for(var j=0;j<auth1.length;j++){ if(auth1[j] == names[i]){ auth[names[i]]=true; break; } } } } console.log(auth);
结果:
js output console.log: ["add", "list", "export", "import", "search"] console.log: ["webname", "age"] console.log: ["add", "list", "export", "import", "search"] console.log: { add: true list: true export: false import: false search: true }
推荐阅读