Last active
February 18, 2016 02:30
-
-
Save lushijie/9f8ad611cf0ce81037d7 to your computer and use it in GitHub Desktop.
函数一次运行包装器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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