Implement an 'argument checker' function?

Issue #19 resolved
Former user created an issue

currently:

foo: function (bar) {
    bar = bar || {}
}

proposal:

// in a util.js or wherever
isDefined: function (val) {
    return typeof val !== "undefined";
}

checkArg: function (val, defaultVal) {
    return aeq.isDefined(val) ? val : defaultVal;
}

// then when in use:
foo: function (bar) {
    foo = checkArg(bar, {});
}

Comments (8)

  1. Rune Gangsø

    I'm wondering if this function should be a "global" variable inside aequery. If it is going to be used often, it would make for cleaner code to just use that, instead of aeq.setDefault every time.

    What do you think?

  2. Rune Gangsø

    In main.js:

    aeq.setDefault = function() {}
    var setDefault = aeq.setDefault
    

    In any other file inside aequery:

    function foo( value ) {
        value = setDefault( value, 'bar' )
        // Do something
    }
    

    Instead of:

    function foo( value ) {
        value = aeq.setDefault( value, 'bar' )
        // Do something
    }
    
  3. Former user Account Deleted reporter

    Ah! Yeah that's much better. Didn't understand that it was a discussion on namespace. Want me to take care of this / give it a shot?

  4. Log in to comment