| "handler" is null or not an object |
| Written by Ben McInturff |
| Thursday, 14 January 2010 16:17 |
|
Have you ever had the error: 'handler' is null or not an object? It seems that the problem results from an improper use of prototype's Event.observe call. Event.observe is a great way to attach events using prototype that gets around the messier ways of attaching handlers that are so yesterday. For example, when I first learned how to code, it was perfectly acceptable to use the window.onload="dostuff" method of attaching a function to the browser's load event. The problem with that method of attachment though is that in the long run it becomes difficult to manage the handlers that have already been subscribed to that event, especially with today's complex web applications. Prototype offers a great way around that with its Event.observe method, which allows one to attach a handler to a window level or even a dom object event, such as link.click. The syntax will look something more like this: The error I was getting actually stems from assigning the return of the function to the handler, in this case leaving out the function() {} syntax: In this case, the error is simple to overcome, but I mention it here for anyone who gets this quirky error message and want's to know why.
|
