Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【2021-07-26】实现一个 once 函数,传入函数参数只执行一次 #15

Open
superDCH opened this issue Jul 26, 2021 · 1 comment

Comments

@superDCH
Copy link
Owner

No description provided.

@superDCH
Copy link
Owner Author

superDCH commented Jul 26, 2021

function once(func) {
  let tag = true;
  return function () {
    if (tag == true) {
      func.apply(null,arguments)
      tag = false;
    }
    return undefined
  }
}

调用:

function getName(name){
     conso.log("获取到名字:",name)
}
let newFc=once(getName)
newFc('aaa') //获取到名字:aa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant