<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title>angular.identity</title>
</head> <body ng-app="indentityExample">
<h1>angular.identity</h1>
<p>
<span>描述:</span><br />
<span>返回他的第一参数的函数,次函数多用于函数编程</span>
</p>
<p>
<span>使用方法:</span><br />
<span>angular.identity(value)</span>
</p>
<p>
<span>参数:</span><br />
<span>value:用于返回</span><br />
</p>
<p>
<span>返回值:</span><br />
<span>value</span>
</p>
<hr />
<div ng-controller="indentitycon"> </div>
</body>
<script src="../../js/angular.1.3.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
angular.module('indentityExample', []).controller('indentitycon', function($scope){
//返回一个数的平方的方法
$scope.square = function(n){
return n * n;
}
//把上一个方法当做参数应用
$scope.getResule = function(fn, val){
return (fn || angular.identity)(val);
}
//定义一个变量
$scope.initVal = 5;
var result = $scope.getResule($scope.square, $scope.initVal);
$scope.aa = $scope.getResule($scope.square, $scope.initVal);
console.log($scope.aa);
})
</script> </html>