'this' vs $ scope ในตัวควบคุม AngularJS
ในส่วน"สร้างส่วนประกอบ" ในหน้าแรกของ AngularJSมีตัวอย่างนี้: controller: function($scope, $element) { var panes = $scope.panes = []; $scope.select = function(pane) { angular.forEach(panes, function(pane) { pane.selected = false; }); pane.selected = true; } this.addPane = function(pane) { if (panes.length == 0) $scope.select(pane); panes.push(pane); } } แจ้งให้ทราบว่าselectวิธีการที่จะถูกเพิ่ม$scopeแต่วิธีการที่จะถูกเพิ่มaddPane thisหากฉันเปลี่ยน$scope.addPaneเป็นรหัสจะแตก เอกสารบอกว่าจริงๆแล้วมีความแตกต่าง แต่ไม่ได้พูดถึงความแตกต่าง: รุ่นก่อนหน้าของ Angular (pre 1.0 RC) อนุญาตให้คุณใช้วิธีการthisสลับแทนกันได้$scopeแต่นี่ไม่ใช่กรณีอีกต่อไป …