"JavaScript" "learning" 3. Function types in JavaScript

Source: Internet
Author: User

In JavaScript, a function is actually an object

The function name is actually a pointer to a function object = = Assigns the function name to null and the function still exists

+ = The function name that uses the sack brackets is to access the function pointer instead of calling the function

1, the function is not overloaded, declaring two functions with the same name, which overrides the former

2, function declaration and function expression

Two ways to declare a function:

function functionname () {Do something}

var functionname = new function () {do something};

The difference between the two approaches is that using alert (functionname) before the latter results in an error.


3, function as a value

The function name can be used as a normal variable, and the function name can be passed as a parameter to another function, or a function can be returned by a function.


4, internal properties of the function

The function has 2 internal objects: arguments and this. Arguments is a parameter array that has a

The Callee property, which points to the function that owns this arguments. This represents the environment object to which the function is executed.


Alert (Arguments.callee)//Return function code

Alert (this)//Return to Object Window

Alert (This.caller)//return undefined


The caller property of the function: Returns the function that called the current function.


5, properties and methods of the function:

Length: Returns the number of arguments to the function

Prototype: returns a reference to the object type prototype

Apply (): Invokes a function in a specific scope. Accepts 2 parameters, scope and parameter array

Call (): Invokes a function in a specific scope, accepts several parameters, the first parameter is scope, and the other parameter is

Arguments passed to the calling function

You can use Call (widow) or apply (window) to extend the scope of the function to all

Bind (): Creates a function instance, and the parameter of bind () is the scope of the instance function.

toLocaleString () and ToString (): Returns the source code of the function




function fun1 () {alert ("good");    } var Newf = Fun1.bind ();      alert (FUN1);           Returns the source code of the function Newf (); Good


This article is from the "Wanghaz Learning" blog, so be sure to keep this source http://10703847.blog.51cto.com/10693847/1697942

"JavaScript" "learning" 3. Function types in JavaScript

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.