JS Anonymous function call method

Source: Internet
Author: User
Tags anonymous

JS Anonymous function call method
Mode 1, call the function, get the return value. The force operator makes the function call execute

View Sourceprint?1 (function (x,y) {

2 alert (x+y);

3 return x+y;

4} (3,4));

Mode 2, call the function, get the return value. Force the function to perform a direct amount of execution and return a reference, and then invoke the execution

View Sourceprint?1 (function (x,y) {

2 alert (x+y);

3 return x+y;

4}) (3,4);

This is also the way many libraries love to call, such as Jquery,mootools.

Mode 3, using void

View sourceprint?1 void function (x) {

2 x = x-1;

3 alert (x);

4} (9);

Mode 4, using the-/+ operator

View Sourceprint?01-function (x,y) {

alert (x+y);

return x+y;

04} (3,4);

05

+function (x,y) {

alert (x+y);

return x+y;

09} (3,4);

10

One--function (x,y) {

alert (x+y);

return x+y;

14} (3,4);

15

++function (x,y) {

alert (x+y);

return x+y;

19} (3,4);

Finally look at the wrong way to call

View sourceprint?1 function (x,y) {

2 alert (x+y);

3 return x+y;

4} (3,4);

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.