Posted By:
26 Aug, 2014 12:15 pm PDT

OOPS with JavaScript

Javascript is known as one of the programming langugaes which possess object oriented capabilites. Please explain.

Attachment:None


OOPS with JavaScript

JavaScript is an Object Oriented Programming (OOP) language. A programming language can be called object-oriented if it provides four basic capabilities to developers:

Encapsulation . the capability to store related information, whether data or methods, together in an object

Aggregation . the capability to store one object inside of another object

Inheritance . the capability of a class to rely upon another class (or number of classes) for some of its properties and methods

Polymorphism . the capability to write one function or method that works in a variety of different ways

Objects are composed of attributes. If an attribute contains a function, it is considered to be a method of the object otherwise, the attribute is considered a property.

 

Object Properties:

Object properties can be any of the three primitive data types, or any of the abstract data types, such as another object. Object properties are usually variables that are used internally in the object's methods, but can also be globally visible variables that are used throughout the page.

The syntax for adding a property to an object is:

objectName.objectProperty = propertyValue;

Example:

Following is a simple example to show how to get a document title using "title" property of document object:

var str = document.title;

 

Object Methods:

The methods are functions that let the object do something or let something be done to it. There is little difference between a function and a method, except that a function is a standalone unit of statements and a method is attached to an object and can be referenced by the this keyword.

 

Methods are useful for everything from displaying the contents of the object to the screen to performing complex mathematical operations on a group of local properties and parameters.

Example:

Following is a simple example to show how to use write() method of document object to write any content on the document:

document.write("This is test");

Was it useful?  




Please login to reply to this problem.