Home >Web Front-end >JS Tutorial >The meaning of javascript callback function

The meaning of javascript callback function

一个新手
一个新手Original
2017-10-14 09:44:181527browse

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);
        }
    }

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")
        }
    })

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!

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