uhlryk / function-overloader Goto Github PK
View Code? Open in Web Editor NEWimprove overloading functions and methods in js
improve overloading functions and methods in js
Overload will have static method any which will return symbol and we will check if there is this symbol
Overload.multiple.*
like Overload.multiple.string
, means that we assume that here there will be multiple string arguments
we should handle case when no cases met.
it can be by some new method "otherwise" or by "when" which will get some new static Overload method like Overload.multiple.any
.
something like
Overload.interface({
name: Overload.STRING,
dosomething: Overload.FUNCTION
})
something like
.when("string", Overload.or("booleam", "number"))
which means execute when we get string and boolean or string and number
That will return only correct functions
Remove set
and change done
to execute. Execute will be a last method which will then start process.
change this
Overload.set("someString", 12345)
.when(Overload.NUMBER, Overload.STRING)
.do(() => Promise.resolve("wrong result"))
.when(Overload.STRING, Overload.NUMBER)
.do(() => Promise.resolve("correct result"))
.when(Overload.NUMBER, Overload.OBJECT)
.do(() => Promise.resolve("wrong result"))
.done()
.then(result => {
expect(result).to.be.equal("correct result");
});
to this
Overload
.when(Overload.NUMBER, Overload.STRING)
.do(() => Promise.resolve("wrong result"))
.when(Overload.STRING, Overload.NUMBER)
.do(() => Promise.resolve("correct result"))
.when(Overload.NUMBER, Overload.OBJECT)
.do(() => Promise.resolve("wrong result"))
.execute("someString", 12345)
.then(result => {
expect(result).to.be.equal("correct result");
});
.when()
.do(() => {
})
above case should handle no arguments in function. current this mean "handle other not handled cases"
Accept anything except listed
.when("number", Overload.not("string"))
Accept also array of types
.when("number", Overload.not(["string", "boolean"]))
and main export will export function creator
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.