interviews.dotnetthread.com

↑ Grab this Headline Animator

Monday, September 1, 2008

oops concept in the javascript

Like C++,vb.net and c#.net we have oops concept in the javascript also

For an example
function myObject(param1,param2)
{

//Private Member Variables
var prop1 = null;
var prop2 = null;
setProp1(param1);
setProp2(param2);

//Private Read Only Member Variable
var prop3 = null;
setProp3("read only");

//Public Method Pointers for Getters/Setters
this.getProp1 = getProp1;
this.setProp1 = setProp1;
this.getProp2 = getProp2;
this.setProp2 = setProp2;
this.getProp3 = getProp3;

//Public Method Pointers for other Actions
this.getProps = getProps;
this.testPrivateMethod = testPrivateMethod;

//Public Methods (they all have pointers)
//Getters and Setters
function getProp1()
{
return prop1;
}
function setProp1(parameter)
{
prop1 = parameter;
}
function getProp2()
{
return prop2;
}
function setProp2(parameter)
{
prop2 = parameter;
}
function getProp3()
{
return prop3;
}
//Setter for prop3 is private - no method pointer
function setProp3(parameter)
{
prop3 = parameter;
}

//Other Actions
function getProps()
{
return "prop1: " + this.getProp1() + "\nprop2: " + this.getProp2() + "\nprop3: " + this.getProp3();
}
function testPrivateMethod()
{
privateMethod();
}

//A Private Method
function privateMethod()
{
setProp1("new prop1");
setProp2("new prop2");
}
}
use the above javascript oops concept for the following link
C:\Documents and Settings\sdebata\Desktop\6355\oopTest.htm

For more reference go to:
http://www.codeproject.com/KB/scripting/edujini_005_JavaScript_OO.aspx

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles