扫一扫分享
Standalone test spies, stubs and mocks for JavaScript. Works with any unit testing framework.
npm install sinon
The following function takes a function as its argument and returns a new function. You can call the resulting function as many times as you want, but the original function will only be called once:
function once(fn) {
var returnValue, called = false;
return function () {
if (!called) {
called = true;
returnValue = fn.apply(this, arguments);
}
return returnValue;
};
}
仅供个人学习参考/导航指引使用,具体请以第三方网站说明为准,本站不提供任何专业建议。如果地址失效或描述有误,请联系站长反馈~感谢您的理解与支持!
手机预览