optional parameters, default values and type-checking for your JavaScript method signatures
ArgueJS is a new JavaScript library that allows you to delightfully extend your methods's signatures with optional parameters,
default values and type-checking.
example
Let's suppose we want to rewrite the well known method range from underscorejs.
Note that documentation says its method signature is range([start], stop, [step]). With ArgueJS we could type just this way:
function range(){
arguments = __({start: [Number, 0], stop: Number, step: [Number, 1]})
for(var i = arguments.start; i < arguments.stop; i += arguments.step)
console.log(i);
}
Repl:
>>> range(3)
0
1
2
>>> range(3, 5)
3
4
>>> range(0, 5, 2)
0
2
4
Take a look at the documentation for more.
Written by zVictor
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Arguments
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#