Tuesday 28 June 2011

Objective JavaScript

Some say that not many uses JavaScript as an objective language.

In my experience objective JS is useful in producing modular architecture, and later customising functions, etc. However, my impression is that if ones who are not familiar with objective programming deal with objective JS, it is very easy to loose the control of borders of objects. This is chiefly because variables have no concept of focus, they can be referred from anywhere.

Anyways, it is delightful to see JS from different perspective.

Object can be created for instance:
if(!window.obj){
    function Obj(){};
}

Then constructor is something like this;
function Obj(){
  this.var1 = a;
  this.var2 = 1; 
}

Then object can be inherited with .prototype method:

SomeObj.prototype = new Obj();

Methods can be implemented by

SomeObj.prototype.method1 = function (){
  statement1;
  statement2; 
}

Instancing can be realised by

obj1 = new SomeObj();

If somebody found errors, better ideas, etc.etc., You are welcome to share your comments on the wall!

No comments:

Post a Comment