Home > Web Front-end > JS Tutorial > body text

The meaning of javascript callback function

一个新手
Release: 2017-10-14 09:44:18
Original
1446 people have browsed it

Simply put, callback function: that is, the function to be executed.

(1) Definition of callback function

##

function add(x,y,fn) {
        /*
        * this.x  this.y:属于add类的全局变量的定义
        * */
        this.x=x||1;
        this.y=y||1;

        if(fn){     /*判断是否有回调函数,有的话执行传入的函数(传入参数)*/
            fn(this.x+this.y);
        }
    }
Copy after login

2) The callback function is usually an anonymous function with a return value

##

  add(1,2,function (v) {//回调函数有返回值
        if(v>0){
            alert("result>0")
        }else{
            alert("result<0")
        }
    })
Copy after login

The above is the detailed content of The meaning of javascript callback function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!