怪我咯2017-04-10 14:38:45
这东西还要封装?
var a = 'foo',b = {};
b['a'] = a;
封装成
var addAttr = function(obj,attr,name){
if(obj && typeof(obj) != 'number' && typeof(name)=='string'){
obj[name] = attr;
}
}
var a = 'foo', b={};
addAttr(b,a,'a');
console.log(b.a);
这样?