In Chapter 9, WTFudge Is Going On?: Troubleshooting MooTools, a discussion of variable type reporting led us to an instance where we could not properly return the type of an undeclared variable. This oddity has its roots in the fact that undefined, undeclared variables cannot be dereferenced during a function call.
In short, undeclared variables can not be used as arguments to a function.
Get ready to see how we can still extend MooTools' typeOf
function by passing a missing variable using the global scope:
// will throw a ReferenceError myfunction(oops_var); // will not throw a ReferenceError myfunction(window.oops_var);
Extend the typeOf
function with a new method and call that rather than the parent method.
// it is possible to extend functions with new methods typeOf.extend('defined',function(item) { if (typeof(item)=='undefined') return 'undefined'; else return typeOf(item); }); //var oops_var; // commented out...