試圖找到AngularJS $rootScope.$broadcast
的一些基本信息,但AngularJS文檔沒有多大幫助。簡單地說,我們爲什麼要使用它?
此外,約翰爸爸的Hot Towel模板中有一個名爲$broadcast
共同模塊中的自定義函數:
function $broadcast() {
return $rootScope.$broadcast.apply($rootScope, arguments);
}
我不明白這是什麼做的。所以這裏有幾個基本問題:
1)$rootScope.$broadcast
是做什麼的?
2)$rootScope.$broadcast
和$rootScope.$broadcast.apply
有什麼區別?
https://developer.mozilla.org/en- US/docs/JavaScript/Reference/Global_Objects/Function/apply – Blackhole
http://mariuszprzydatek.com/2013/12/28/sharing-data-between-controllers-in-angularjs-pubsub-event-bus-example/ –
' $ rootScope。$ broadcast.apply()'被使用,因爲如果你想要pa將特殊的'arguments'對象轉換爲另一個函數,則需要使用'apply()'(而不是'call()')。 除了@Blackhole鏈接到應用的MDN頁面之外,您還可以查看['arguments']上的條目(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference /功能/參數)。 –