Home >Web Front-end >JS Tutorial >javascript custom callback function sample code_jquery

javascript custom callback function sample code_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:35:201080browse

If you call it directly in function a, then the callback function will be restricted. But using functions as parameters has the following benefits: when you do a(b), function b becomes a callback function, and when you can also do a(c), function c becomes a callback function. If you write functiona(){...;b();}, you lose the flexibility of variables.

Copy code The code is as follows:

function a(index,callback){
callback(index);
}

function b(index){
alert(index);
}

a(10000,b);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn