Thursday, December 14, 2006

Ahhh, JavaScript error messages.

<sarcasm>
They are the epitome of the user friendly error message. Developers love them, because they always tell you exactly where the problem is. Absolute error message perfection.
</sarcasm>

Below is an example of one of these messages that a friend sent:

Nice, eh?

You can tell EXACTLY what the problem is. That... thing... is null or not an object! And we've even got a line number, too!

NOTE: The above message was generated by a script I wrote a while back that is kicked off by the window.onerror event that fires when JavaScript exceptions are thrown. It posts to an application which then emails the developers in question.

posted on Thursday, December 14, 2006 11:05:47 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, February 15, 2006

For those two or three who missed it, Yahoo! released two libraries yesterday: the Yahoo! Design Patterns Library and the Yahoo! User Interface Library. I particularly like the UI library. First of all, it was released under as open source, so as long as you include the copyright at the top, it looks like you can use it. I checked out their JavaScript code and it looks pretty good. It seems that the whole object { name : value }* notation of declaring objects is becoming more popular. It is also becoming much more common to see entire frameworks being developed (I'm thinking of the JavaScript libraries that come with Atlas). Anyway, interesting stuff. It will be a lot easier to add some nice, production quality JavaScript to pages now.

* Instead of:

var newObject = new function () {
   this.name = value;
}

It is:

var newObject = {
   name: value;
}

posted on Wednesday, February 15, 2006 7:53:14 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Thursday, February 09, 2006

Now this is different, eh? A post on JavaScript instead of .NET! This is a little trick I came up with to add outerHTML functionality in Firefox. For those who aren't familiar with outerHTML, it is an IE addition to the DOM that will return the element's HTML PLUS it's innerHTML. Is it really needed? No, but it can help with debugging sometimes. Here's the code:

if (document.body.__defineGetter__) {

       if (HTMLElement) {

              var element = HTMLElement.prototype;

              if (element.__defineGetter__) {

                     element.__defineGetter__("outerHTML",

                           function () {

                                  var parent = this.parentNode;

                                  var el = document.createElement(parent.tagName);

                                  el.appendChild(this);

                                  var shtml = el.innerHTML;

                                  parent.appendChild(this);

                                  return shtml;

                           }

                     );

              }

       }

}

This entire thing revolves around the __defineGetter__ method off of objects. To be honest, I don't know if it is standard JavaScript or if it is just a Mozilla extension. It makes extending the DOM a lot easier, though. I probably wouldn't trust this in a production environment, but I wouldn't hesitate to use it for testing.

posted on Thursday, February 09, 2006 1:21:16 PM (Central Standard Time, UTC-06:00)  #    Comments [0]