Posts Tagged ‘Prototype’

Mixin Classes as a way to reuse JavaScript code

Sunday, January 3rd, 2010

This is a useful example of how you can augment a Class to have a particular method but not by using strict inheritance or by duplicating the relevant code for each Class you have. I came across this technique (known as “Mixin Classes”) while reading the book “Pro JavaScript Design Patterns”.

(more…)

How to add useful utility methods to JavaScript

Sunday, September 13th, 2009

If you find in your day to day JavaScript work that a particular method or function is missing from the core language you can always just add it in yourself by taking advantage of the prototypal nature of the JavaScript language and modifying an object’s hidden prototype property.

Every object has a prototype property which links to an empty object. By adding methods to this hidden object you can augment the original Function.

(more…)