javascript - js 萬物皆對象的問題
問題描述
各位好,由于鄙人js基礎(chǔ)較差,在工程中遇到基礎(chǔ)問題較多,尤其是“萬物皆對象”這個理念。就比如:
1、$scope.dataArr={};我要為其增加屬性,$scope.dataArr.currTopic=xxxx就是錯誤的;然而$scope.dataArr[currTopic]是正確的。
2、$scope.dataArr 中有一個key 名為 currTopic,初始value為[ ]。我要為currTopic的value增加值,即想push元素到[ ]中去。使用$scope.dataArr.currTopic.push( xxx ) 又是錯誤的。$scope.dataArr[currTopic].push( xxx ) 是正確的。
這是為什么?
問題解答
回答1:點(diǎn)訪問和[]訪問屬性是一樣的,并不會報錯,測試結(jié)果下圖:
請貼出錯誤提示信息
var $scope={};$scope.dataArr={};$scope.dataArr.currTopic='XXXXX';$scope.dataArr['currTopic']='YYYYYY';$scope.dataArr.currTopic=[];$scope.dataArr.currTopic.push('AAAAAAA');$scope.dataArr['currTopic'].push('BBBBBB');
相關(guān)文章:
1. python - 如何對列表中的列表進(jìn)行頻率統(tǒng)計?2. javascript - 如何用最快的速度C#或Python開發(fā)一個桌面應(yīng)用程序來訪問我的網(wǎng)站?3. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙4. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?5. django - Python error: [Errno 99] Cannot assign requested address6. Python2中code.co_kwonlyargcount的等效寫法7. python小白,關(guān)于函數(shù)問題8. linux運(yùn)維 - python遠(yuǎn)程控制windows如何實(shí)現(xiàn)9. python小白 關(guān)于類里面的方法獲取變量失敗的問題10. mysql數(shù)據(jù)庫做關(guān)聯(lián)一般用id還是用戶名
