201506231015_ "JavaScript authoritative Guide (sixth edition)-functions as namespaces, closures," (p181-193)

Source: Internet
Author: User

1. function as a namespace. form: var Somefn = (function () {var a = 0;return function f () {//...};} ());

2. closures.

Parameters of an external function cannot be accessed directly within a closure unless the external argument is stored as a variable. For example: var outerarguments = arguments;

3. Properties, methods, constructors of functions

A.
Arguments.length; (expected number of arguments passed in)

Arguments.callee.lenth; (number of actual arguments passed in)

B. Prototype properties

Constructors inherit properties and methods from the prototype object;

C. Call () and apply ()

The first parameter is the "parent object to invoke the function"

form: function. Call (object); function. Apply (object);

4. Bind ();--binds the function to the entire object; (returns a Function object)

For example:

function Square (x) {return x*x}; var obj = {X:2}; var newObj = Square.bind (obj,obj.x);   Console.log (NEWOBJ()); 4 Note the brackets, because "square.bind (obj,obj.x);" is a function type!!

5. toString ();

6. function (); constructor

A. Pass in any number of string arguments;

B. var fn = new Function ("X", "Y", "return x + y;");  fn (2,3); 5

c. var scope = "global"; function constructfunction () {var scope = "Local"; return new function ("return scope")// None method to obtain local};

7.

201506231015_ "JavaScript authoritative Guide (sixth edition)-functions as namespaces, closures," (p181-193)

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.