0
我正在通過tutorial創建角度過濾器。我對一些實現感到困惑,它涉及到基本的JavaScript。這裏是鱈魚片段:自定義過濾器語法
// on the app object, the method filter is called passing a name parameter and the function
myApp.filter('reverse', function() {
return function (text) {
// now a function that accepts text as a parameter is returned
return text.split("").reverse().join("");
// the text parameter splits, revers, and joins the text parameter.
}
});
我的問題是爲什麼不能寫這樣的東西呢?在第二行的第一個片段中返回函數的目的是什麼?
myApp.filter('reverse', function (text) {
return text.split("").reverse().join("");
});
因爲你傳給'filter'的函數是依賴注入。 – elclanrs