JavaScript functions, BOM

Source: Internet
Author: User
Tags array length

"Declaration and invocation of functions"
format of the 1.>>> function declaration: Formal parameters can be declared without Var
declare using the function keyword:
function Name (parameter 1, parameter 2,......) {
//function Body
return result;
}

>>> function call format:
function name (value of parameter 1, value of parameter 2,......)

2. Some highlights of function declarations
the declaration of the ① function name must conform to the small hump rule (first letter lowercase, then each word capitalized);
② parameter list, can have parameters, can have no parameters. It is called the parameter function, and no parameter function.
③ A parameter list when declaring a function, called a "parameter list" (the name of a variable);
A list of arguments when a function is called, called the "argument list" (the value of the variable);
function, the actual valid argument depends on the assignment of the argument, and the parameter that is not assigned will be undefined

④ function If a return value is required, return the result using a return.
when calling a function, use the variable var variable name = function name (), receive the return result,
If the function does not return a value, the received result is undefined

Scope of variables in the ⑤ function:
In a function, a variable declared with VAR, which defaults to a local variable of the function, is used only inside the function;
variables declared without VAR, default to global variables (global variables in functions, must be used after function calls)
A function 's formal parameter list, which is a function local variable and is used only inside the function.

the Declaration and invocation of the ⑥ function has no precedence, that is, the invocation of the function can precede the declaration.

"anonymous function"
1. Declare an anonymous function and assign it directly to an event.   
Window.onload = function () {}
The function following the event can of course be any function, which can be a regular function call.
Window.onload = func ();

2. Declaring an anonymous function using a function expression:
declaring function: var func = function () {}
call Functions: Func ();//equivalent function name
>>> using an anonymous function expression, the invocation statement must be followed by an error after declaring the statement (comparing the difference between a regular function declaration and a call?). )

      Use function expressions to separate function names from function declarations, making functions more flexible

3. Declare and invoke the anonymous function directly using the self-executing function:
①!function () {//function Body} (); Use the start of any operator, recommended!
② (function () {//function Body} ( ));//use () enclose the anonymous function and the following parentheses
③ (function () {//function body}) ; Use () to wrap an anonymous function expression only
Three types of writing features:
① structure clear, beginning Plus!, end Plus (). Clear structure Recommended!
② can indicate that the anonymous function and the following () are a whole. Recommended!
③ cannot indicate that the function and the following () are a whole. Not recommended!

>>>1 cannot call an argument function 2,3 can call a parameter function

"Arguements Object"
1. Function: The argument list for the assigned value when saving the calling function
>>> When you call a function and assign a value using an argument, the argument is actually saved to the arguements array, and the parameter can be called using arguments[n], even if there are no formal parameters.

the number of 2.arguments arrays depends on the argument list, regardless of the parameter. (Order starting from 0)
But when the parameters, arguments, and arguement of the nth position are present, the shape participates in the arguement is synchronous (that is, the value of one is modified in the function and the other changes synchronously)
>>> after an array declaration, elements outside the array length in the array are undefined, or can be said to be unassigned array elements

3.arguements.callee is an important property of arguements for returning a reference to the function where arguments is located;
Arguments.callee () can invoke its own function execution ;   

calling the function itself within a function is called recursion, so Arguments.callee () is a common way of recursive invocation.

"This"
point to the scope of the function call statement, the caller of the function

"Properties of the Screen object"

Console.log (screen.availheight);//Screen available height
Console.log (screen.height);//Screen height
Console.log (screen.availwidth);//Screen available width
Console.log (screen.width);//Screen width

"Location Object"

protocol://hostname (IP address): Port number (not written, default Apache 80 port)
/file path (pathname)? [Pass parameters] (name1=value1) & (name2=value2) #[anchor Point]

Console.log (LOCATION.HREF); Full path
Console.log (Location.protocol); There are http:https:ftp:mailto:file:
Console.log (Location.pathname); File path
Console.log (Location.port); Port number
Console.log (Location.search); From the back part of the beginning
Console.log (Location.hostname); Host name (IP address)
Console.log (Location.host); Host name + port number
Console.log (Location.hash); Anchor Point starting from #

"Navigator":
appName: Product name
appversion: Product version number
useragent: User agent information
platform: System Platform
Plugins: Check plugin information for browser installation

navigator.plugins: Returns an array that contains all the plugins installed by the browser
>>> The main attributes are:
Description: Plugin description information
FileName: The file name of the plugin on the local disk.
Length: Number of plugins
Name: Plug-in name

Navigator.mimetypes Browser plug-in, supported file types
description:mime Type Description
Enabledplugin: Support for this type of browser plugin
suffixes: Possible suffix names for this type
the Type:mime type. such as: Image/x-icon text/css

Common methods for the "Focus" Window object :
all methods in the >>>window object can omit the previous window, such as close ();
1.prompt (): Pop-up window receives user input
2.alert (): Pop-up window warning
3.confirm (): Button prompt with confirm/Cancel
4.close (): Close the current browser tab
5.open (): Reopen a window, passing in Parameters (Url,name, window features)
window features different browser effective, so you can not

6.setTimeout: Set delay execution, only once
two parameters: function name (unable to pass parameter), time (indicates how many seconds delay to execute)
a return value: ID
7.setInterval: Set Timer to execute every n milliseconds
two parameters, the function name of the function to be executed (do not add parentheses to the argument list), or write the anonymous function directly.
time: Time interval
The function name is passed as a parameter and cannot be passed (callback function)


8.clearTimeout: Clear Delay execution
One parameter: SetTimeout returns the ID
9.clearInterval: Clear Timer
Pass in a parameter: Call SetInterval to return an ID, pass the variable to accept the ID, and pass in as a parameter clearinterval

JavaScript functions, BOM

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.