javascript - The problem of everything in js being an object
为情所困
为情所困 2017-06-16 09:19:22
0
2
843

Hello everyone, due to my poor foundation in js, I encountered many basic problems in the project, especially the concept of "everything is an object".
For example:

1,
$scope.dataArr={};
If I want to add attributes to it, $scope.dataArr.currTopic=xxxx is wrong;
However, $scope.dataArr[currTopic] is correct.

2. There is a key named currTopic in
$scope.dataArr, and the initial value is [ ].
I want to add value to the value of currTopic, that is, I want to push elements to [].
Using $scope.dataArr.currTopic.push(xxx) is wrong again.
$scope.dataArr[currTopic].push( xxx ) is correct.

why is that?

为情所困
为情所困

reply all(2)
曾经蜡笔没有小新

The attributes of click access and [] access are the same, and no error will be reported. The test results are as follows:

学霸

Please post error message

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");
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template