This is first post about Angular.js source code analysis.
Angular.js start with following code.
1 2 3 4 5 | bindJQuery(); publishExternalAPI(angular); jqLite(document).ready(function() { angularInit(document, bootstrap); }); |
Before it starts, it will go though some interesting code.
Angular.js forEach.
what it to do is assigning value to array.
1 2 3 | forEach('multiple,selected,checked,disabled,readOnly,required,open'.split(','), function(value) { BOOLEAN_ATTR[lowercase(value)] = value; }); |
forEach function is to loop through the list of object.
and “Call” anonymous function.
1 2 3 4 5 | function forEach(obj, iterator, context) { for(...){ iterator.call(context,obj[key],key,obj); } } |
The following code is example of function call.
You will see output value is 2 and 3.
It will ignore 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <html> <head> <script language="javascript"> function displayDate(iterator){ iterator.call(1,2,3,4); } displayDate(function(value,key){ console.log(value); console.log(key); }); </script> </head> <h1>forEach Test</h1> <p id = "demo"> This is a paragraph.</p> <button type="button" onclick="displayDate()">Display Date</button> <body> </body> </html> |