js函数只执行一次
function once(fn) {
let executed = false;
return function() {
if(!executed) {
executed = true;
fn.apply(this.arguments);
}
};
}
const sayHelloOnce = once(function() {
console.log('Hello');
});
sayHelloOnce(); // 输出: 'Hello'
sayHelloOnce(); // 不再输出任何内容