Wednesday, March 11, 2009

Object Oriente Java Script!!

Writing JavaScript in an object-oriented way helps us to simplify complex task at client side. JavaScript supports all the familiar object-oriented programming concepts. JavaScript supports creating/defining new objects and with help of prototype property we can achieve the object oriented behavior.

Lets start with the normal java class and then will see how it looks like with javascript

class Test {
//property and methods
}
Test test = new Test();  // creating an object of type Test

JavaScript:
function Test() {
//property and methods
}

var test = new Test(); // creating a new object

Note that the function keyword is overloaded, it beahaves as normal procedure function and can also be used as constructor.
var temp = Test() // normal function call
var temp = new Test() // as a constructor

No comments:

Post a Comment