CallBack Function in JavaScript)

Source: Internet
Author: User

In jQuery, we often use callback functions. In JavaScript, callback functions can be passed as parameters and executed after the current function is executed. How to Use the callback function? There are two types of callback functions: 1. Callback functions without parameters; 2. Callback functions with parameters.Using callback functions without parameters in jQuery$. Get ("myhtmlpage.html", myCallBack callback will call myCallBack after jqueryreceives myhtmlpage.html. Here, myCallBack is not a string, but a defined method name. Here, myCallBack is a method without any parameters.
Using callback functions with parameters in jQuery

$.get( "myhtmlpage.html", function() {  myCallBack( param1, param2 ); });Here, we pass an anonymous function, and then call our defined parameter callback function within the anonymous function. Why is an anonymous function used for processing instead of directly passing our callback function? For example, $. get ("myhtmlpage.html", myCallBack (param1, param2); here, myCallBack (param1, param2) returns the value processed by the function, not a function. 


This article is from the "SG-YYZ" blog, please be sure to keep this source http://sgyyz.blog.51cto.com/5069360/1297946

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.