check out my latest app: Icon Preview
and my latest blog post
Ensure a function is only called once
License: MIT License
check out my latest app: Icon Preview
and my latest blog post
Every example uses onetime
but IDEs will import it as oneTime
because that's the name in index.js
and index.d.ts
Should I update the documentation (to use oneTime
) or the code/types (to onetime
)?
I think onetime
can return TFunction & {__onetime: true}
or a Function that extends both the argument and a private OneTimedFunction
type.
var onetime = require('onetime');
var i = 0;
var foo = onetime(function (a) {
i++;
a = a + i;
return a;
});
console.log(foo(1));
console.log(foo(2));
console.log(foo(3));
Hello,When I use this moudles,I Think I can get the value as 0 every time,But I get the result like this :2,2,2
It'd be roses and rainbows if there was an accessible property/flag to indicate if the function had been called the one time or not. Please let me know if you'd like me to elaborate. I thought about filing this under mem
but this seemed like an appropriate first stop.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.