Giter VIP home page Giter VIP logo

argumenter's People

Contributors

trecenti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

boneskull

argumenter'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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.