lib/index.js
function once(evt, handler) {
            var thisArg = arguments[2] === undefined ? null : arguments[2];

            var wrapper = undefined,
                self = this;
            // add a wrapper around the handler and listen to the requested event
            this.on(evt, wrapper = function () {
                for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
                    args[_key4] = arguments[_key4];
                }

                try {
                    handler.apply.apply(handler, [thisArg].concat(args));
                } catch (err) {
                    console.error("ONCE handler received an error: " + err.message + ", " + JSON.stringify(err));
                } finally {
                    // remove the wrapper so that the event doesn't call us again
                    self.off(evt, wrapper, thisArg);
                }
            }, thisArg);
        }
function once(evt, handler) {
            var thisArg = arguments[2] === undefined ? null : arguments[2];

            var wrapper = undefined,
                self = this;
            // add a wrapper around the handler and listen to the requested event
            this.on(evt, wrapper = function () {
                for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
                    args[_key4] = arguments[_key4];
                }

                try {
                    handler.apply.apply(handler, [thisArg].concat(args));
                } catch (err) {
                    console.error("ONCE handler received an error: " + err.message + ", " + JSON.stringify(err));
                } finally {
                    // remove the wrapper so that the event doesn't call us again
                    self.off(evt, wrapper, thisArg);
                }
            }, thisArg);
        }
function once ( evt , handler ) { var thisArg = arguments [ 2 ] === undefined ? null : arguments [ 2 ] ; var wrapper = undefined , self = this ; // add a wrapper around the handler and listen to the requested event this . on ( evt , wrapper = function ( ) { for ( var _len4 = arguments . length , args = Array ( _len4 ) , _key4 = 0 ; _key4 < _len4 ; _key4 ++ ) { args [ _key4 ] = arguments [ _key4 ] ; } try { handler . apply . apply ( handler , [ thisArg ] . concat ( args ) ) ; } catch ( err ) { console . error ( "ONCE handler received an error: " + err . message + ", " + JSON . stringify ( err ) ) ; } finally { // remove the wrapper so that the event doesn't call us again self . off ( evt , wrapper , thisArg ) ; } } , thisArg ) ; }
Register a handler that will execute once for an event. Otherwise the same as `on`.
@param {string|Array<string>|Object} evt
@param {function} handler
@param {Object} [thisArg]
Register a handler that will execute once for an event . Otherwise the same as on .