The distinction between a function declaration and an expression of a function
function declaration:
function function name ( parameter: Optional ) { body }
function expression:
function name (optional)( parameter: Optional ) { function body }
function foo () {}//declaration because it is part of the program
var bar = function foo () {}; expression, because it is part of an assignment expression
New function Bar () {}; expression, because it is a new expression
(function () {
function bar () {}//declaration because it is part of the body of the function
})();
There is also a function expression that is less common and is enclosed in parentheses (function foo () {}), which is the reason for the expression because the parentheses () are a grouping operator whose interior can only contain expressions
Second, module mode
- Modular, REUSABLE
- Encapsulates variables and function, and the global namaspace does not touch, loosely coupled
- Only expose methods of available public, all other private methods are hidden
Third, the first time to make their own functions
window.onload=function () {
var Song=document.getelementbyid ("Myfirst");
Song.addeventlistener ("click", Changeboxes,false);
}
function Changeboxes (evt) {
var oform=document.forms["MyForm1"];
var Ocheckbox=oform.hoby;
alert (evt.target.name);
For (var i=0;i<ocheckbox.length;i++)
if (evt.target.name<0)
ocheckbox[i].checked=!ocheckbox[i].checked;
else if (evt.target.name>0)
ocheckbox[i].checked = 1;
Else ocheckbox[i].checked = 0;
<p id= "Myfirst" >
<input type= "button" value= "Select All" Name= "1" >
<input type= "button" value= "All not selected" Name= "0" >
<input type= "button" value= "Reverse Selection" name= "-1" >
</p>
}
The first function is an execution function obtained by getElementById ("Myfirst") to the P tag.
Events are monitored by AddEventListener, and event delegates are implemented by binding events on the parent p of 3 input tags
And after further understanding the event delegate, through the target property in the Click event to point to the object you clicked, can further dynamically get the properties of the Click Object, so as to determine the truth of different click objects to achieve different operations.
!!!!!!!!!!! Used in the evt.target.name where the evt is the parameter;
Also, you need to know that if you add an event like <element onclick= "function (this)" >, the This is a pointer to the element
November 26, 2014
JavaScript notes (2) (Evernote)