欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JavaScript 反射和属性赋值!

程序员文章站 2022-07-01 13:45:31
结果: ......
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
}