js- 实现属性名的拼接 obj['name']


   obj.name---->obj[name] 这两种调用方式一样,使用obj.name内部转换成 obj['name'], 使用obj['name']更快。
  obj['name'] 里面必须是字符串

      

var jack = {
  wife1: {name: 'susan'},
  wife2 :{name: 'heimei'},
  wife3:{name:'baimei'},
  wife4 :{name: 'huangmei'},
  sayWife : function (num){
  return this['wife'+ num];
}
}

  jack.sayWife(2);

转载于:https://www.cnblogs.com/jie-xuan/p/11310878.html

你可能感兴趣的:(js- 实现属性名的拼接 obj['name'])