您的位置:首页 > Web前端 > JavaScript

【学习笔记】JavaScript编码规范-属性

2015-05-15 14:49 519 查看
使用点表示法访问属性。

var objA = {name:A,age,30};
//good
var nameA = objA.name;

//bad
var nameA = objA['name'];

//God bless!


用变量访问属性是要用下标表示法([])

var objB = {name:B,age;30};

function getProp(prop){
return objB[prop];
}

var nameB = getProp('name');

//God bless!


1:6 And God said,Let there be a firmament in the midst of the water,and let it divide the waters from the waters
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: