About JavaScript function objects those obfuscation analysis _js object-oriented

Source: Internet
Author: User
The function object in JS is a fascinating thing, but because he is too flexible and often confusing, I post some code:

Most people have this shorthand:
Copy Code code as follows:
function Test () {}


The whole book of the Jsvascript language:
Copy Code code as follows:
var test = function () {}


Functions can run immediately and assign values:
Copy Code code as follows:

var test = function () {} ()//test = = undefined
var test2 = function () {return ' Sugar Pie '} ()//Test2 = = ' Sugar Pie '

But the function shorthand does not run directly, the following code will complain:
Copy Code code as follows:
function Test () {} ()//Syntaxerror:syntax Error


Normal after wrapping with the "()" Run:
Copy Code code as follows:
(function Test () {}) ();


In fact, this function name test has no meaning, the removal of the anonymous function, can still automatically execute the function in vivo code, commonly used to write anonymous functions:
Copy Code code as follows:
(function () {}) ();


Anonymous functions can also be said to be "beautiful" point:
Copy Code code as follows:
(function () {} ());


See this, just contact JS brother is it going crazy? I have seen my project to engage in C-language cab, I saw the anonymous function immediately after the petrochemical ...

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.