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){
        for(var j=0;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
}

Original: https://www.cnblogs.com/raphael5200/p/11748376.html
Author: Bodi
Title: JavaScript 反射和属性赋值!

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/535892/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球