Obfuscation Analysis on javascript function objects

Source: Internet
Author: User

The function object in js is a fascinating thing, but it is often confusing because it is too flexible. I will post some code below:

Most people are abbreviated as follows:
Copy codeThe Code is as follows: function test (){}

The entire book jsvascript is written as follows:
Copy codeCode: var test = function (){}

Functions can be run immediately and assigned values:
Copy codeThe Code is as follows:
Var test = function () {} () // test = undefined
Var test2 = function () {return 'sugar browsed '} () // test2 = 'sugar browsed'

However, function abbreviations cannot be run directly. The following code reports an error:
Copy codeCode: function test () {} () // SyntaxError: syntax error

If the package is normal after the "()" operator is used:
Copy codeThe Code is as follows: (function test (){})();

In fact, this function name "test" is meaningless. After it is removed, it becomes an anonymous function, and the code in the function body can still be automatically executed. Commonly used anonymous function Syntax:
Copy codeThe Code is as follows: (function (){})();

The write of anonymous functions may also be "beautiful:
Copy codeThe Code is as follows: (function (){}());

Seeing this, is it crazy to get started with JavaScript? I once saw my C-language developer in my project. I met anonymous functions and immediately became 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.