Is there sence to check all arguments and other conditions in code, if I know, I never pass wrong argument and it should work fine ( say I already made some checks outside of that code ).
Example:
this code:
/**
* Applies function to all elements of array in specified
* context.
* If array is empty, returns null.
*/
MyNameSpace.foreach = function(arr, callback, context) {
if (!(arr instanceof Array)) {
throw new Error('first argument is not an array');
}
if (typeof callback !== 'function') {
throw new Error('callback is not a function');
}
if (typeof arr.length === 'undefined') {
throw new Error('Length undefined');
}
var con = typeof context === 'object' ? context : window;
var i = arr.length;
if ( i <= 0 ) {
return null;
}
for ( j = 0; j < i; j++ ) {
callback.call(con, j, arr[j]);
}
}
could be:
MyNameSpace.foreach = function(arr, callback, context) {
var con = typeof context === 'object' ? context : window;
var i = arr.length;
if ( i <= 0 ) {
return null;
}
for ( j = 0; j < i; j++ ) {
callback.call(con, j, arr[j]);
}
}