JavaScript functions are a class-one citizen, functions can exist alone, regardless of function definition within that function, can be called by other objects
For example:
function person (name)
{
var walk = function ()
{
Alert ("I'll Run");
}
}
Walk.call (window);
Although the walk function is a person, the function can be called by another object.
Methods for defining functions
The first type:
functoion function Name (P1, p2)
{
function execution Body;
return p1 + p2;
}
The second type//use more
var tt = fuction (P1, p2)
{
return p1 + p2;
}
Third Kind
New function (P1,P2, P3......PN)
{
PN is the executing body;
}
Focus: Each time you define a JS function, you produce one class at a time.
----------------------------------------------
Use the difference without using Var:
→ If you use var to define a variable, the program will force a new variable to be defined.
→ If a variable is not defined using VAR, the system will first search for the variable in the current context, and the system will redefine a new variable only if the variable does not exist.
-----------------------------------------------
JavaScript is not overloaded with methods, it is according to the latest definition of the method
-----------------------------------------------
function call;
Call directly:
P.walk ();
Invoke the function with the call () method;
Function name. Call (caller, parameter 1, parameter 2 ...);
The caller. function (parameter 1, parameter 2, ...) = functions name. Call (caller, parameter 1, parameter 2 ...)
Call with the Apply () method
Name of the function. Apply (caller, arguments)
For example myfun.apply (window, [12, 3, 4]);
Summary of JavaScript functions