Skip to content

Instantly share code, notes, and snippets.

@lushijie
Last active February 18, 2016 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lushijie/9f8ad611cf0ce81037d7 to your computer and use it in GitHub Desktop.
Save lushijie/9f8ad611cf0ce81037d7 to your computer and use it in GitHub Desktop.
函数一次运行包装器
function onceWraper(func){
return function(){
if(func){
var ret = func.apply(this,arguments);
func = null;
return ret;
}else{
console.log('非第一次运行不再执行');
return;
}
}
}
function abc(){
console.log('这是abc函数');
}
var abcOnce = onceWraper(abc);
abcOnce();//这是abc函数
abcOnce();//非第一次运行不再执行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment