Closed function: Another way of writing anonymous functions in JavaScript, creating a function that executes without naming it at the beginning
Example:
1)
(function() { var str = ' Welcome to my home page '; alert (str); A+ +;}) ();
2)
! function () { var str = ' Welcome to my homepage '; alert (str); A+ +;} ();
3)
~function() { var str = ' Welcome to my homepage '; alert (str); A+ +;} ();
Note: Add in front of the closed function; You can avoid some unnecessary problems ~
Closures: function nesting functions, intrinsic functions can refer to parameters and variables of external functions, parameters and variables are not reclaimed by garbage collection mechanism.
Closure function:
1) A variable is stationed in memory for a long time and can be used to cycle the value of the index.
var aLi = document.getelementsbytagname (' li '); for (var i=0;i<ali.length;i++) { (function (i) { function () { alert (i); } }) (i); }
2) Private variable counter, external inaccessible, avoid the pollution of global variables.
var count = aa (); function AA () { var a = 1; function BB () { a++ ; return A; } return BB; } Alert (count ()); Alert (count ());
Built-in objects:
1) Document
Document.referrer//Get the address of the previous Jump page (requires server environment)
2) Location
Window.location.href//Get or reset the URL address;
Window.location.search//Get address Parameters section;
Window.location.hash//Get the page anchor point or hash value;
<! DOCTYPE html> window.onload = function () { var Dat = Window.location.search; var ospan = document.getElementById (' Span01 ' var arr = dat.split (' = ' var a = Arr[1]; ospan.innerhtml = A; </script>
3) Math
Math.random//Get a random number of 0-1;
Math.floor//downward rounding;
Math.ceil//upward rounding;
js--closed functions, closures, built-in objects