Click to See Complete Forum and Search --> : Objects in Javascript


vikrampschauhan
January 25th, 2005, 07:29 PM
I believe objects in Javascript are essemtially the same as objects in C#(or Java).

For eg, I have a code snippet:

var xml=new ActiveXObject("Microsoft.XMLDOM");
xml.async=false;
xml.load("autoBody.xml");

var xsl=new ActiveXObject("Microsoft.XMLDOM");
xsl.async=false;
xsl.load("autoBody1.xsl");

document.write("<center>"+xml.transformNode(xsl)+"</center>");


Here, when we say:
var xml=new ActiveXObject("Microsoft.XMLDOM");

an object of the ActiveXObject class is allocated on the heap and its reference is given to xml.

(We have declared xml as a var, we could have said:
ActiveXObject xml=new ActiveXObject("Microsoft.XMLDOM"); instead of declaring it simply a var, and its type would be determined at runtime).

Now, the object that variable xml refers to contains the public data member async
and the method load(these members are called later using: xml.async=false;
xml.load("autoBody.xml"); ).

Is my interpretation of the functionality correct here?

This would mean that Javascript is an object oriented language.

I believe VBScript is also object oriented?


Thanks
Vikram

visualAd
January 28th, 2005, 11:37 AM
I think it would be more correct to say that Javascript is an obkect based language.

True object orientated languages allow for the four concepts of object orientated programming:

Abstraction - ignorance of the objects internal behaviour. :thumb:
Encapsulation - information hiding and protection of internal data :thumbd:
Inheritance - extending an object template to include specific functionality :thumb:
Polymorphism - responding to the same message in a different way depending on the typeof object :thumb:

Inheritance in JS is not however achieved through the use of class templates. An initial instance the object must first be created and its underlying prototype modified though the objects prototype property.