JavaScript類屬性的訪問方式
復制代碼 代碼如下:
var fish = {
head : 1,
tail : 1,
feature : {
speak : false,
swim : true
}
}
復制代碼 代碼如下:
console.log(fish.head);//1
console.log(fish.tail);//1
console.log(fish.feature);//Object { head:1, tail:1, feature: Object}
復制代碼 代碼如下:
console.log(fish['head']);//1
復制代碼 代碼如下:
console.log(fish[head]);//錯誤!
復制代碼 代碼如下:
for(var prop in fish) {
console.log(fish[prop]);
}
新聞熱點
疑難解答
圖片精選