A, JS declare a function in three ways:
1, // function declarations (function declaration) assignment phase occurs in the code parsing
function H () {
// H
}
2, // function expression (function expression) occurs in the code assigned operational phase: the function expression requires a semicolon at the end of the statement, indicating the end of the statement. And declarative function defined without ending curly braces semicolon:
var H = function () {
// H
}
3, using the Function constructor is not recommended in this way
var add2 = new Function (); call: add2 ()
Second, function characteristic
1, to enhance the function of a priority than the variable lift higher, and will not be covered by variable declarations, but will be covered by variable assignment.
2, in function, the parameter is a local variable
3, in the function return statement that a function can return ahead of schedule. When the return is executed, the function returns immediately.
A function always returns a value, if this value is not specified, it will return undefined .
Third, the wording of several functions performed immediately
. 1,
(function () {
Alert (. 1);
}) ();
2、
(function () {
alert(2);
}());
3、
! function () {
alert(3);
}();
Fourth, in this function points
aa = {var
name: "an xz",
Age: 20 is,
RUN: function () {
the console.log (the this);
}
}
aa.run (); // the this target point aa
NOTE: When a function is stored as a property of the object, method call it. When the method is called, this is bound to this object.
BB function () {
the console.log (the this);
}
BB (); // points to the this window object
;: The constructor calls the new mode function name ()
: the this object pointing out new
Fifth, the function parameter arguments
When the function is called, there will be an array of arguments. not a real array of arguments, it's just an array of objects of class, it has a length property, but without the associated array of methods.