once

var once = function(obj, evtType, handler) {
    var f = function() {
        //console.log(arguments)
        handler.apply(window, arguments)
        obj.removeEventListener(evtType, f, false)
    }

    obj.addEventListener(evtType, f, false)
}

once(document.querySelector('button'), 'click', function(event) {
    console.log(event)
})
原文地址:https://www.cnblogs.com/jzm17173/p/4552408.html