;(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