function once(fn){ let down = false; return function(){ if(!down){ down = true; return fn.apply(this,arguments); } } } let pay = once(function(money){ console.log(`支付:${money}RMB`) }) let pay1 = once(function(money){ console.log(`支付:${money}RMB`) }) pay(5); pay(5); pay1(12); pay1(12);
function once(fn){ let down = false; return function(str){ if(!down){ down = true; return fn(str); } } } let pay = once(function(money){ console.log(`支付:${money}RMB`) }) let pay1 = once(function(money){ console.log(`支付:${money}RMB`) }) pay(5); pay(5); pay1(12); pay1(12);