JavaScript callback function

Source: Internet
Author: User

The callback function is used to pass one function as a parameter to another function as the return result in another function.

Here is a simple example of a callback function: Tom went to the store to buy something, just out of stock, the shopkeeper asked him to take the information recorded in the book, a few days and there is goods, the shopkeeper on the book to find Tom's phone, the shopkeeper to find the phone is a callback function.

function Outputphone (name) {    + "Phone: 10000");} // functions that use callback functions function SearchInfo (name, callback) {    callback (name);} //  searchinfo ("Tom", Outputphone);

The advantage is that you can use the existing parameters, call different functions, such as Tom above, if you do not get the number, you can also change a callback function, get home address ah .... Age, Ah, something like that.

Examples of common callback functions in jquery:

$ (' #id '). On ("click", Callback);

The callback function is always around ..... It's just that we're accustomed to ....

JavaScript callback function

Related Article

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.