例子:爲什麼UnderscoreJS的_.extend()方法將AngularJS承諾複製到擴展對象?
$scope.post = Posts.get({id: id});
scope = _.extend({}, $scope);
alert($scope.post.id); // undefined
alert(scope.post.id); // exception - post is not defined
我覺得我做的事情顯然是錯誤的,但我想不出什麼。我預期的post
參考淺複製到新的對象:
alert($scope.post.id); // undefined
alert(scope.post.id); // undefined
$scope.post === scope.post; // true
你不是真的添加任何東西,所以你可以做。 'scope = $ scope。$ new()'。另外發布將是一個承諾的權利? – PSL 2014-09-22 22:23:26
@PSL謝謝。我確實把它看作是我的用例的解決方案。但是,如果這種方式行不通,我幾乎退出網絡開發,所以我很想知道答案。 – colllin 2014-09-22 22:25:50
是@PSL,'post'將是一個承諾。我將更新問題標題以使用正確的術語。 – colllin 2014-09-22 22:27:14