JavaScript 自定义事件

//自定义事件
function Event() {

    var handles = [];

    //绑定事件
    this.addHandle=function(fn) {
        handles.push(fn);
    }

    //触发事件
    this.exec = function () {
        if (handles.length > 0) {
            handles.forEach(function (value, index, array) {
                value();
            });
        }
            
    }
}
原文地址:https://www.cnblogs.com/caoyc/p/5727014.html