O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending typeOf, fixing undefined var testing

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.

Getting ready

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);

How to do it...

Extend the typeOf function with a new method and call ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required