函数返回本身的第一个参数。这个函数一般用于函数风格。
格式:angular.identity()
<!DOCTYPE html> <html ng-app="Demo"> <head> <meta charset="UTF-8"> <title></title> <script src="framework/angular.js"></script> <script type="text/javascript"> (function () { angular.module("Demo", []) .controller("testCtrl", function testCtrl() { var getResult = function (fn, val) { return (fn || angular.identity)(val); //angular.identity(val) == fn(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 }); }()) </script> </head> <body> <div ng-controller="testCtrl"> </div> </body> </html>