angular.identiy
描述:
返回它第一参数的函数. 此函数多用于函数是编程.
使用方法:
angular.identity(value);
参数详解:
Param | Type | Details |
---|---|---|
value | * | to be returned. |
返回值:
传入的value
实例代码:
<!DOCTYPE HTML>
<html ng-app="exampleApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="angular.min.js"></script>
<script>
var exampleApp = angular.module('exampleApp',[]);
exampleApp.controller('ShowController',['$scope', function($scope){
$scope.result = "";
$scope.double = function(n){
return n*2;
}
$scope.triple = function(n){
return n*3;
}
$scope.answer = function(fn, val){
return (fn || angular.identity)(val);
}
$scope.show = function(){
$scope.result = $scope.answer($scope.double, 3);
}
}]);
</script>
</head>
<body>
<div id="test">博弈网络科技</div>
<div>
<div>
angular.identity
</div>
<div id="myCtrl" ng-controller="ShowController">
<input type="button" id="btn" ng-click="show()" value="answer" />
:<input type="text" id="answer" ng-model="result" />
</div>
</div>
<hr>
</body>
</html>