@ The beast's NG API learning--angular.identity and Angular.noop
Angular.identity
The function returns the first parameter of itself. This function is generally used for function style.
Format: angular.identity ()
Using code:
<script>
Angular.module ("Demo", [])
. Controller ("Testctrl", ["$scope", function ($scope) {
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
}])
</script>
Angular.noop
An empty function that does not perform any action. This function is generally used for function style.
Format: Angular.noop ();
Post code:
<script>
Angular.module ("Demo", [])
. Controller ("Testctrl", ["$scope", function ($scope) {
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
}])
</script>
@ Beast all these 22 API understanding is also a bit drunk, in general, these two methods are used to write functions, according to the Code of the demo and running results, @ The beast thinks their role is to prevent the function from passing in null or undefined or other objects that cannot be manipulated. Because if you get rid of these two, when you pass the function call to the null/undefined/or other objects can not be executed, then the console is directly error ...
The two source code is also very simple, on 2-3 lines, and each line is not more than 20 letters.
Well, today write 2 @ Beast API Learning to understand it, recently have to learn to hurry and write faster, or else can not write those better usage or something .... Today, my little friend asked me questions and asked me to write as soon as possible ... But time is limited. Pro t_t
Hey! @ Beast, your NG API dropped--angular.identity and Angular.noop