JavaScript Object Oriented Feature

In this article you learn the basics of JavaScript and create your first JavaScript program.

JavaScript Object Oriented Feature

 JavaScript Object Oriented Feature

     

In this article you learn the basics of JavaScript and create your first JavaScript program.

What is Object Oriented Feature
The ASP.NET and Visual Studio 7.0 are making important contributions to improvement of the web development experience. Unfortunately, this is also a tendency created among developers to limit their interaction with JavaScript. it is Clearly JavaScript is valuable for adding client-side functionality to the web pages. However the ASP.NET programming models suggest that developers produce page layout while emitting client-side JavaScript from ASP.NET controls. As a consequence, this model tends to limit JavaScript to procedural adjuncts. This is rather unfortunate because it severely limits the power of an object-oriented scripting language that developers can be use to write rich and reusable client-side components. JavaScript  object oriented will be presented in a series of  three type article. The first installments provided background on  JavaScript supports the main principles of object-oriented programming. The second  part demonstrates how JavaScript constructs can be used to build a class inheritance framework and write scripts supporting in JavaScript class hierarchy. The third and final installment  to use the JavaScript class framework to build object-oriented client-side abstractions of ASP.NET user controls.

There are Some reasons of way JavaScript Object Oriented Capability are not utilized:
There are tendency of client-side operations to be discrete favorite procedures. 
The ASP.NET programming model are controls suggests limiting JavaScript to the functional adjuncts. 
Legacy JavaScript lacked key features such as exception handling and inner functions and JavaScript its supported for object- oriented programming .  
 

 Example:

<html>
<head>
<Script language="JavaScript">
function MyClass()
{
this.myData = 10; 
this.myString = "my frist program";
}
var myClassObj1 = new MyClass();
var myClassObj2 = new MyClass();
myClassObj1.myData = 20;
myClassObj1.myString = "Obj1: my second program";
myClassObj2.myData = 30;
myClassObj2.myString = "Obj2: last program"; 
alert( myClassObj1.myData ); 
alert( myClassObj1.myString ); 
alert( myClassObj2.myData ); 
alert( myClassObj2.myString ); 
</script>
</head>
</body>
</html>

Object-Oriented Programming
The Object Oriented programming is a computer programming paradigm. Object Oriented programming is that computer program may be seen as comprising a collection of individual units and objects, that is on each other, as opposed to a traditional view in which a program may be seen as a collection of functions or procedures, or simply as a list of instructions to the computer. Each object is capable of receiving messages, processing data, and sending messages to other objects. The Object-oriented programming is claimed to promote greater flexibility and maintains in programming, and is widely popular in large-scale software engineering. Further the more proponents of OOP claim that Object-Oriented programming  is easier to learn  those new to computer programming than previous approaches and that the OOP approach is often simpler to develop and to maintain, lending itself to more direct analysis or coding, and understanding of complex situations and procedures than other programming methods.

Object:
The Object an instance of a class and object is the run-time manifestation of a particular exemplar of a class. The class of dogs which contains breed types, an acceptable exemplar would only be the subclass 'collie'; "Lassie" would then be an object in that subclass. Each object has own data, though the code within a class a subclass or an object  may be shared for economy. Thus, object-oriented languages must allow code to be reentrant. 

Encapsulation
The Object-Oriented program using the myclass as defined permits accessibility of its internal data representation as well as this methods and variable names global in scope increasing the risk of name collisions. The Object-Oriented program Encapsulation supports data hiding and the concept of viewing objects as self-contained entities providing services to consumers. The principle of information hiding is the hiding of  The design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. Protecting is a design decision involves providing a stable interface which shields the remainder of the program from the implementation . Encapsulation is a  modern programming languages of  the principle of information hiding itself in a number of ways, including encapsulation and polymorphism.

Example: 

<html>
<head>
<Script language="JavaScript">
function MyClass()
{
var m_data = 15;
var m_text = "indian";
this.SetData = SetData;
this.SetText = SetText;
this.ShowData = DisplayData;
this.ShowText = DisplayText; 
function DisplayData()
{
alert( m_data );
}
function DisplayText()
{
alert( m_text );
return;
}
function SetData( myVal ) 
{
m_data = myVal;
}
function SetText( myText ) 
{
m_text = myText;
}
}
var Obj1 = new MyClass();
var Obj2 = new MyClass();
Obj1.SetData( 30 );
Obj1.SetText( "Obj1: my cuntry" );
Obj2.SetData( 60 );
Obj2.SetText( "Obj2: my first javaScript progarm" );
Obj1.ShowData(); 
Obj1.ShowText(); 
Obj2.ShowData(); 
Obj2.ShowText(); 
</script>
</head>
</body>
</html>