angular.noop

angular.noop 是一個不執行任何操作的函式,當你需要提供一個什麼都不做的函式引數時,你傳遞 angular.noop

angular.noop()

angular.noop 的一個常見用途是為一個函式提供一個空回撥,否則當函式傳遞給它時會丟擲一個錯誤。

例:

$scope.onSomeChange = function(model, callback) {
    updateTheModel(model);
    if (angular.isFunction(callback)) {
        callback();
    } else {
        throw new Error("error: callback is not a function!");
    }
};

$scope.onSomeChange(42, function() {console.log("hello callback")});
// will update the model and print 'hello callback'
$scope.onSomeChange(42, angular.noop);
// will update the model

其他例子:

angular.noop() // undefined
angular.isFunction(angular.noop) // true