JavaScript notes (2) (Evernote)

Source: Internet
Author: User

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
    1. Modular, REUSABLE
    2. Encapsulates variables and function, and the global namaspace does not touch, loosely coupled
    3. 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.