Advanced Topics in JaxerContents
__noSuchMethod__By default, an attempt to call a method that doesn't exist on an object results in a TypeError being thrown. This behavior can be avoided by defining a function at that object's __noSuchMethod__ member. The function attached will be invoked with two arguments, the name of the method called and an array of the arguments passed in the method call.
The default Mozilla
implementation omits allowing this to happen on the anonymous global (window) object so while a call to the method in the
window namespace (e.g., Jaxer repairs this core JavaScript behavior by making the anonymous global also trigger the __noSuchMethod__ handler if defined. This was used, to give a real world example, to develop the autoloading component of the ActiveJS framework. To demonstrate the difference between the old and new handling of missing methods, the sample below shows different results when the handler is triggered by server code (new behavior) versus client code (old behavior). The second method call on the client results in an exception, whereas both calls are trapped by the handler on the server side. The try/catch blocks avoid messy browser exceptions. Note: The following sample will only work in Firefox as it illustrates in the feature between the Jaxer and Mozilla engines. Using the global __noSuchMethod__ handlerResult of running the __noSuchMethod__ example
Jaxer Extensions
Jaxer is built with a simple method for adding your own capabilities to the core Jaxer object, extensions. An extension is written in
JavaScript, in a file stored in the The simplest extension would look like this: (function(){
Jaxer.MyProp = 'hey I extended Jaxer !!!';
})();
Jaxer ships with a sample extension,
Looking at the sample extension's code, in the next block, note that the key work is done in the onLoad and onUnload event handlers.
The two functions add and remove, respectively, the actual functions which the extension use to do the heavy lifting by calling
Record page and script requests with a Jaxer extension |
