标签:bsp var blog str return null efi color angular
一个不执行任何操作的空函数。这个函数一般用于函数风格。
一个不执行任何操作的空函数。这个函数一般用于函数风格。
格式:angular.noop();
(function () {
angular.module("Demo", [])
.controller("testCtrl", testCtrl);
function testCtrl() {
var _console = function (v) {
return v * 2;
};
var getResult = function (fn, val) {
return (fn || angular.noop)(val);
};
var firstResult = getResult(_console, 3);//6
var secondResult = getResult(null, 3);//undefined
var thirdResult = getResult(undefined, 3);// undefined
};
}())
区别于angular.identity()
(function () {
angular.module("Demo", [])
.controller("testCtrl", testCtrl);
function testCtrl() {
var getResult = function (fn, val) {
return (fn || angular.identity)(val);
};
var result = getResult(function (n) { return n * 2; }, 3); // result = 6
var null_result = getResult(null, 3);// null_result = 3
var undefined_result = getResult(undefined, 3);// undefined _result = 3
};
}())
标签:bsp var blog str return null efi color angular
原文地址:http://www.cnblogs.com/ms-grf/p/6979432.html