- changed status to resolved
Implement an 'argument checker' function?
Issue #19
resolved
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)
-
Account Deleted reporter -
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?
-
Account Deleted reporter I don't get how this would be implemented; can you give an example?
-
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 }
-
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?
-
That would be great, thanks!
-
Account Deleted reporter Makes setDefault global variable, updates calls (re:
#19)→ <<cset 8464d725f4d2>>
-
- changed milestone to 1.0 Release
- Log in to comment
main.js: Adds setDefault for undefined/null explicit checking; implements instead of 'or' var assignments (resolve
#19)→ <<cset 4f66b3366403>>