当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JavaScript 反射和属性赋值!

JavaScript 反射和属性赋值!

2019年10月28日  | 移动技术网IT编程  | 我要评论
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
}

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网