argumenter's People
Forkers
boneskullargumenter's Issues
order of when() calls matters too much when dealing w/ types
The below code will (perhaps unexpectedly) execute the callback for the Object
strategy.
var Foo = function Foo() {
};
function myFunc() {
argumenter(arguments)
.when(Object, function(obj) { /* .. */ })
.when(Foo, function(obj) { /** .. */ });
}
myFunc(new Foo());
The below code will execute the callback for the Foo
strategy.
var Foo = function Foo() {
};
function myFunc() {
argumenter(arguments)
.when(Foo, function(obj) { /** .. */ })
.when(Object, function(obj) { /* .. */ });
}
myFunc(new Foo());
Other issues exist too; if your strategy is an array of strategies, then it must be placed before any singular strategies: [Object, String]
must come before Object
.
Perhaps the, ahem, strategy to deal with this would be to store all of the strategies and determine precedence during the done()
function. This could be done by examining constructors and prototypes, then creating some sort of precedence tree... but that sounds like a lot of work.
if strategy is Array, argumenter thinks it's an object
The type checking is too loose; typeof([])
will return 'object'
. This comes into play if the Object
strategy comes before the Array
one.
example:
function myFunc() {
return argumenter(arguments)
.when(Object, function(obj) {
return 1;
})
.when(Array, function(arr) {
return 2;
})
.done();
};
console.log(myFunc([])); // 1
Also, someArray instanceof Object
is true
. It should only check instanceof
if someArray
is not an Array
.
I've corrected both these issues and will amend my PR.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.