zoukankan      html  css  js  c++  java
  • 向JS对象添加和删除事件

    this.removeEventListener = function (obj, ename, func) {
        var store = obj[this.addEventListener.pre + ename];
        if (!store) {
            return;
        }
        var i = store.indexOf(func);
        if (i < 0) {
            return;
        }
        obj[this.addEventListener.pre + ename].splice(i, 1);
    };
    this.addEventListener = function (obj, enames) {
        if (arguments.length < 2) {
            return;
        }
        if (!this.addEventListener.pre) {
            this.addEventListener.pre = "god_" + Math.random() * Number.MAX_VALUE;
        }
        if (typeof arguments[1] == "string") {
            var ename = arguments[1];
            var fullname = "on" + ename;
            if (!(fullname in obj)) {
                var store = this.addEventListener.pre + ename;
                if (!obj[store]) {
                    obj[store] = [];
                }
                Object.defineProperty(obj, fullname, {
                    set: function (v) {
                        obj[store].push(v);
                    }
                });
                var notice = ename === "notice" ? "notice" : "notice" + ename;
                obj[notice] = function () {
                    for (var i = 0; i < obj[store].length; i++) {
                        try {
                            obj[store][i].apply(obj, arguments);
                        } catch (e) {
                            console.log(e.message);
                        }
                    }
                };
            }
        }
        if (typeof arguments[2] === "string") {
            var narguments = [obj];
            for (var i = 2; i < arguments.length; i++) {
                narguments.push(arguments[i]);
            }
            this.addEventListener.apply(this, narguments);
        }
    };
  • 相关阅读:
    程序保护机制
    ubuntu单独安装DDMS
    Linux Syste m Call Table
    任意程序添加ShellCode
    解析结构化异常处理(SEH)(第一部分)
    CONTEXT(线程结构体)
    WINNT.H
    Html的空格显示
    随机变量的联合分布
    期望和期望的性质
  • 原文地址:https://www.cnblogs.com/ly45/p/6016164.html
Copyright © 2011-2022 走看看