码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 反射和属性赋值!

时间:2019-10-27 18:57:41      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:蚂蚁   arch   put   zone   color   col   add   object   type   

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
}

 

JavaScript 反射和属性赋值!

标签:蚂蚁   arch   put   zone   color   col   add   object   type   

原文地址:https://www.cnblogs.com/raphael5200/p/11748376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!