From AngularJS documentation
angular.identity: angular.identity(value);
A function that returns its first argument. This function is useful when writing code in the functional style.
angular.identity: angular.identity(value);
A function that returns its first argument. This function is useful when writing code in the functional style.
function transformer(transformationFn, value) {
return (transformationFn || angular.identity)(value);
};
Example:
var app = angular.module('demoApp', []).controller( 'DemoController', function($scope) { /* * lets have two demo functions */ $scope.demoFunction1 = function(inputVal){ console.log("First function called with parameter : "+inputVal); }; $scope.demoFunction2 = function(inputVal){ console.log("Second function called with parameter : "+inputVal); }; /* * To call above functions in functional way */ $scope.identityFunction = function(fn, val){ return (fn||angular.identity)(val); } $scope.identityFunction($scope.demoFunction1, 19); $scope.identityFunction($scope.demoFunction2, 209); });
Plunker: https://plnkr.co/edit/h0hBCZih58Wuwu2ozm50?p=preview
Good Day :)
1 Comments
Thanks, It's useful.
ReplyDelete