The various ways that the function executes

Source: Internet
Author: User

;(function() {    /** * Declare a function first.     * Note that it is not possible to execute the parentheses with parentheses after execution, because the parser treats it as a function declaration. * @param {String} msg * @return {[type]}*/    functionCommon (msg) {Console.info (msg+ "Declare the function first, then call!" ")    }    /** * Common execution mode. Declare the function first, then use a statement, and add () after the method name*/Common ("Common invocation method,"); /** * Called by call, normal functions and constructors, can be called by call*/Common.call (NULL, "common invocation method,"); /** * via apply call, normal function and constructor, can be called by apply*/common.apply (NULL, ["Common invocation Method,"]); /** * Convert function to expression * There are many ways to convert a function into an expression, such as parentheses () and JavaScript &&, xor, comma, +,-,~,!,new,void, etc. operators can disambiguate between function expressions and function declarations 
    */        /** * function plus a parenthesis to convert it to function expression * @param {String} msg parameter * @return {[type]} [description]*/     (function(msg) {Console.info (msg+ "Declare the function first, then call!" ")     })("Common invocation method,"); /** * The function is followed by a parenthesis, and a parenthesis is nested in the outer layer, converted to a function expression and executed*/    (function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,")); /** * Name function expression, can be directly followed by parentheses and passed in parameters (if there are parameters) * @param {[String]} MSG [description] * @return {[type]} [Descripti On]*/    varCommon1 =functionCommon (msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * Anonymous function expression, can be directly followed by parentheses and passed in parameters (if there are parameters) * @param {[String]} MSG [description] * @return {[type]} [Descripti On]*/    varCOMMONN2 =function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * through the void operator, convert it to an expression, followed by a parenthesis, so that it executes * @param {[String]} MSG [description] * @return {[type]} [Descripti On]*/    void function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * Through the new operator, convert it to an expression, followed by a parenthesis, so that it executes * @param {String} msg [description] * @return {[type]} [description] */    New function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * Through the && operator, convert it to an expression, followed by a parenthesis, let it execute * @param {String} msg [description] * @return {[type]} [DESCR Iption]*/    true&&function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * by using the comma operator, convert it to an expression, followed by a parenthesis, and let it execute * preceded by a semicolon is to distinguish it from the preceding statement * @param {String} msg [description] * @return     {[Type]} [Description]*/    ; true,function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * through the plus operator, convert it to an expression, followed by a parenthesis, so that it executes * preceded by a semicolon to differentiate it from the preceding statement * @param {String} msg [description] * @return     {[Type]} [Description]*/    ; +function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * by using the minus operator, convert it to an expression, followed by a parenthesis, and let it execute * preceded by a semicolon to differentiate it from the preceding statement * @param {String} msg [description] * @return     {[Type]} [Description]*/    ; -function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * through the ~ operator, convert it to an expression, followed by a parenthesis, let it execute * preceded by a semicolon is to distinguish it from the preceding statement * @param {String} msg [description] * @return {     [Type]} [Description]*/    ; ~function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,"); /** * Pass the! operator, convert it to an expression, followed by a parenthesis, and let it execute. If you are returning a Boolean type, do not execute this way, * preceded by a semicolon to differentiate it from the preceding statement * @param {String} msg [description] * @return {[type]} [desc Ription]*/    ; !function(msg) {Console.info (msg+ "Declare the function first, then call!" ")    } ("Common invocation method,");} ())

The various ways that the function executes

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.