Custom events are a fact of life. The Observer Pattern is indespensable. YUI supplies a custom event object - but to get it, you’ve got to include about 8 kilobytes of library in your project. Granted, YUI supplies much, much more than just an event object - but sometimes you don’t need all that. You just need a way for objects to talk to each other. Introducing a bare-bones event object that’s good enough for most situations! It’s not as flexible as YUI’s, but it gets the job done.
Simple Javascript Custom Event Object
March 30th, 2009Javascript Inheritance benchmarks, redux
March 26th, 2009The other day I posted examples of Douglas Crockford’s parasitic Javascript inheritance method. I’d like to qualify some of my claims with some benchmarks using JSLitmus. The skinny: Parasitic inheritance is, indeed, faster. It’s slower to initialize, but unless you’re creating thousands and thousands of instances, that shouldn’t be a problem. It’s faster on calling superclass methods, and calling non-overridden methods. And you don’t need a bulky library to do it. Read on for the results. Read the rest of this entry »
Javascript Inheritance to protect your variables
March 18th, 2009Javascript inheritance is a multi-horned beast. You can use classical inheritance to make things work a little bit more like Java, or you can subscribe wholeheartedly to doing things Javascript’s way.
Doing things Javascript’s way can be a boon, once you wrap your head around it. You don’t need any helper functions to help you out with this. You don’t need a library to implement useful inheritance, like jQuery or Prototype. You gain the benefits of being able to define private variables for your objects. You do lose a little bit in terms of memory usage. But these days, memory is cheap - and Javascript engines are only getting faster. So why not make it easy on yourself, as a developer - and your users, as downloaders?
You’re also limited in that it’s difficult for an overridden method to access the object’s parent implementation. However, I’m firmly of the belief that if you need to do that, you’re doing it wrong. So, without further ado, let’s delve into how to use Javascript to inherit in style - the Crockford Way.
Read the rest of this entry »
Our basic knowledge of economic health is poisoned.
March 2nd, 2009Over the past 60 years, politicians have changed how inflation and unemployment numbers are calculated. They are completely inaccurate. We are actually experiencing exponential inflation right now - but the official government numbers don’t tell us this.
Private object members via closures
March 1st, 2009In almost any object oriented language, you can define access levels for variables in objects. You can in JavaScript, too, but it’s not quite as clear cut as adding a “public” or “private” key word to your object definition. Once you understand how closures work, though, it’s pretty obvious how to implement private member properties and methods. Read the rest of this entry »
Creative Commons Salon, 2009
February 27th, 2009I had the pleasure to attend the February Creative Commons Salon on the 26th. Sitting in For Your Imagination’s studio, some sixty folks sipped on free (as in beer) beer, watching speakers from Thingiverse, Blip.tv, and Indaba Music. Interesting things are happening in the realm of collaborative media, but there’s a signal to noise problem. Read on for comments about each, and some proposed solutions. Read the rest of this entry »
The Strategy Pattern (Part 1)
February 21st, 2009The Strategy Pattern is more useful for programming languages that do not support first-class functions. Fortunately, JavaScript treats everything as an object, and allows for run-time object modification. That enables the use of the strategy pattern quite nicely.
Here’s a simple example for changing the behavior of an object without hard-coding the behavior options into the object itself. It allows for flexible changing of object behavior down the road, without having to refactor an entire code block.
Faking Interfaces in Javascript
February 21st, 2009Tired of futzing with Expression Engine.
February 21st, 2009So, I’m switching over to wordpress. Admin area is much easier to use. Don’t know about themes yet. I’ll get on top of making one eventually.
I’m only bringing one post over from the old blog - the one on JavaScript Interfaces. The first set of posts here will be implementations of common design patterns in JavaScript.
Here’s to hoping it will legitimize the language in the minds of some, and help others to write JavaScript that actually makes sense.

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=068cf54f-b443-4cae-88a9-874b2315ac09)