LM Tech's blog

Software Architecture & Design Patterns

As explained in the post "Javascript Classes", javascript objects inherits properties and methods from its prototype objects. Due to this behavior is possible to extend a native object by adding custom properties to its  prototype object.

In Javascript is available the "String" native object which wrap the "string" primitive data-type and provides a number of helper methods (charAt(), indexOf(), slice(), split(), replace(), ...).

Lets see how to extend this native object with the "paddingLeft" and "paddingRight" functionalities: More...



Despite being javascript an object oriented language, it doesn't use classes. Infact JavaScript is prototype based, not class based.
With javascript you can define and create your custom objects in many ways.

Direct Instance:

var o = new Object();
o.fName = "John";
o.lName = "Smith";
o.getFullName = function(){ return this.fName + " " + this.lName; };

The example above creates a new object's instance and adds two properties and one method. More...