JavaScript 反射和属性赋值! - Go语言中文社区

JavaScript 反射和属性赋值!


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
}

 

版权声明:本文来源博客园,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://www.cnblogs.com/raphael5200/p/11748376.html
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2019-11-17 12:44:57
  • 阅读 ( 1177 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢