DEV Community

loading...

Discussion on: Refactor davidwalsh's debounce function using ES6 arrow and more

Collapse
kelvinzhao profile image
Kelvin Zhao

How would you refactor the 'once' function?

function once( fn, context ) {
    let result
    return function() {
        if( fn ) {
            result = fn.apply( context || this, arguments )
            fn = null
        }
        return result
    }
}