[function declaration and invocation]
1. Format of function declaration:
Function name (parameter 1, parameter 2,....) {
//function body
return result;
}
Function name (value of parameter 1, value of parameter 2,....)
>>> function call format
Direct call: function name (value of parameter 1, value of parameter 2,....)
Event Invocation: Event name = "function name ()";
2, a few highlights of the function declaration:
The declaration of the ① function name, must conform to the small hump rule (first letter lowercase, then each word letter capitalized) The
② parameter list, which can have parameters or no parameters. are called the parameter function and the parameterless function respectively. The
③ argument list when declaring a function, called the parameter list (the name of the variable);
A list of arguments when a function is called, called the "argument list" (the value of the variable); In the
function, the actual valid value depends on the assignment of the argument, and the parameter that is not assigned is undefined; The
④ function can return a result if it needs to return a value.
when calling a function, the var variable name = function name () is used to accept the return result.
If the function does not return a value, the accepted result is undefined; Scope of variables in the
⑤ function:
In a function, a variable declared with VAR, which defaults to a function local variable, is used only in function content;
Variables declared without Var, the default is a global variable, (global variables in the function, must be used after the function electrophoresis)
function of the parameter list, as a function of local variables, only inside the function;
The
⑥ function is declared with a function call, with no successive points. That is, the invocation statement can precede the declaration statement.
[Declaration and invocation of anonymous functions] "focus"
1. Declare an anonymous function and assign it directly to an event
Window.onload=function () {}
2. Declare an anonymous function using a function expression:
declaring function Expressions: var func=function () {}
Call function Expression: func ();
>>> when an anonymous function expression is used, the call statement must be followed by an error after the statement is declared (the difference between the general function declaration and the call)
3. Use the self-executing function declaration and invoke the anonymous function directly:
!function (parameter 1) {} (value of parameter 1)//start with any operator, general use "! 】
(function () {} ())//use () enclose the anonymous function and the following parentheses
(function () {}) ()//use () to wrap only anonymous function expressions
Characteristics:
① structure clear, beginning add! , End Plus (). Not easy to mess, recommended use;
② can indicate that the anonymous function and the following () as a whole, recommended to use;
③ cannot indicate that the anonymous function and subsequent () are a whole and are not recommended for use;
The order in which code is run in JS
Console.log (ABC);
var abc=10;
function FuncN () {}
FuncN ();
JS in the code to run, will be checked, loaded, that is, variable declarations, functions and other operations;
And then the execution phase (variable assignment is the execution phase)
The declaration of a function belongs to the load stage, and the call to the function is in the execution phase, so the function's call statement is written before the function declaration statement, without any relationship.
The above code execution process:
----Check the load----
var num;
function FuncN ()
----Execution Phase----
Console.log (ABC);
abc=10;
FuncN ();
[function Internal Properties]
"Arguments Object "
1. Function: The argument list of the assigned value for saving the calling function.
>>> when we call a function and assign a value using an argument, the argument is actually saved to the arguments array,
Parameters can be called using arguments[n], even without formal parameters
2. The number of arguments arrays, depending on the argument list, is independent of the parameter; (Order starting from 0)
However, when the parameters, arguments, and arguments of the nth position are present, the shape participates in the arguments is synchronous.
(That is, one of the values is modified in the function and the other is synchronized)
3. Arguments.callee is an important attribute of arguments, which is used to return the reference of arguments function;
Arguments.callee () can invoke its own function execution;
In the function calls itself the wording, called recursion, so Arguments.callee () is a recursive invocation of the usual way;
"This"
Point to the scope of the function call statement, that is, who called the function, this is who;
[BOM]
[Screen Object]:
Console.log (screen.width);//Screen width
Console.log (screen.height);//Screen height
Console.log (screen.availwidth);//Usable width
Console.log (screen.availheight);//Available height = screen height-bottom taskbar
[Location Object]:
The full URL path
Protocol://Host name (IP address): Port number/file path? Pass-through parameters (Name1=value1 & Name2=value) #锚点
Console.log (location);
Console.log (location.href);//full path
Console.log (Location.protocol);//Path Protocol Http:https:ftp:file:mailto:
Console.log (location.pathname);//File Path section/start
Console.log (Location.port);//Port number
Console.log (Location.search);//From the beginning of the Future part
Console.log (location.hostname);//Host name (IP address)
Console.log (location.host);//host name + port number
Console.log (Location.hash);//#开始的锚点
function Locationassign () {
Loads a new document. After loading, it can be rolled back.
Location.Assign("http://www.baidu.com");
}
function Locationreplace () {
Replace the new document with the new document. Cannot be rolled back after replacement.
Location.Replace("http://www.baidu.com");
}
function Locationreload () {
Reload the current page
Reload (TRUE): Reload document from server
Reload (): Refresh the current page locally
Location. Reload (true);
}
[history]:
1, History.length: The number of browsing history list;
2, History.forward (); Go ahead and pour a previous page
3, History.back (); Back to the next page
4, History.go (0); Jump to any location on the history page list
Position flag: The current page is 0; the previous page is 1; the next page is-1;
[Navigator Object]
Console.log (navigator.appname);//Product Name
Console.log (navigator.appversion);//Product version number
Console.log (navigator.useragent);//user agent Information
Console.log (navigator.platform);//System platform
Navigator.plugins: Returns an array that detects all plugins installed by the browser
>>> Main properties:
Description: Plug-in Description information
FileName: The file name of the plugin on the local disk
Length: Number of plug-ins
Name: Plug-in name
Navigator.mimetypes: Browser plug-in, supported file types
>>> Main properties:
Description:mime type description
Enabledplugin: Support for this type of browser plugin
Suffixes: Possible suffix name for this type
The type:mime type, for example: Image/x-iocon text/css
Common Methods for window objects "focus"
All methods in the >>>window object can omit the previous window, such as close ();
1, prompt: Pop-up window to receive user input;
2. Alert: Pop-up window warning
3. Confirm: Prompt box with confirmation/Cancel button;
4, close: Close the current browser options;
5. Open: Reopen a window, incoming data: url/window name/Window feature
6, SetTimeout: Set delay execution, will only execute once
7, SetInterval: Set the timer, cycle every n milliseconds to execute once
Two parameters: Number of function/milliseconds to execute (separated by commas)
8, Cleartimeout: Clear delay
9. Clearinterval: Clear Timer
Incoming parameters: Returns an ID when calling SetInterval, receives the ID through the variable, and passes in the clearinterval.
JS function and BOM