Skip to content

Commit 45f28d8

Browse files
committed
polyfill for lodash once function
1 parent 18fd9a1 commit 45f28d8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lodash_Once

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function once(func) {
2+
let called;
3+
return function () {
4+
if (func) {
5+
called = func.apply(this, arguments);
6+
func = null;
7+
}
8+
return called;
9+
};
10+
}
11+
12+
const output = once((a, b) => console.log("calculating sum...", a + b));
13+
output(10, 20);
14+
output(10, 20);
15+
output(10, 20);
16+
output(10, 20);

0 commit comments

Comments
 (0)