Skip to content

您好问下您一些初级的问题。 #4

@neodreamtale

Description

@neodreamtale
const onlyOnce = (fn) => (...args) => {
    if (fn === null) {
        throw new Error('Callback was already called')
    }
    const callFn = fn
    fn = null
    return callFn(...args)
}

JS新手。。。没有看懂您这块的写法。尤其是 (fn) => (...args) =>{/code/}这段这是一个参数是fn的函数。。然后后面是在做什么?您能大概说说吗?
另外还想问下fn = null这个在这个代码块里置null不是应该只影响这个代码块吗,并不会影响外面传进来的fn吧?
之前一直在做java,js太生疏了,请您斧正。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions