Hello friends.
In this post i will explain javascript objects and
How to create objects? and
How to access objects properties and property values? and
Types of javascript objects? and
What are all objects available in javascript? and
Uses of javascript objects?
The above concepts are explain easily and briefly
Lets come....
JAVA SCRIP OBJECTS:
We know very well Javascript is a Scripting Langauge.
But A Javascript is an Object Oriented Programming(OOP) Langauage. A programming lanaguage can be called Object Oriented. If it provides a capabilities to developers, the capabalities are
In this post i will explain javascript objects and
How to create objects? and
How to access objects properties and property values? and
Types of javascript objects? and
What are all objects available in javascript? and
Uses of javascript objects?
The above concepts are explain easily and briefly
Lets come....
JAVA SCRIP OBJECTS:
We know very well Javascript is a Scripting Langauge.
But A Javascript is an Object Oriented Programming(OOP) Langauage. A programming lanaguage can be called Object Oriented. If it provides a capabilities to developers, the capabalities are
- Class
- Object
- Abstraction
- Encapsulation
- Aggregation
- Inheritance
- Polymorphism
Bust am explain here Object only....
Objects:
- Objects are composed of attributes. If attributes contains a function. A function consider to methods and property.
- Object properties are usually denoted a variables that are use internally in objects methods. But it can globally visibled that are used throughout the document or page.
- Objects method accessed to following syntax
Syntax:
object_name.object_property=property_value
Example:
book.title="Javascript";
book.author="Mariz";
How to create Object?
- Create a object use new key word. its used to create an instanceof an object.
- To create an object the new operator is followed by the contructor.
- A constructor is a function that creates and initializes an object
- Javascript provides special consctructor function is object.
- the object property to the object not a variable and not to be defined keyword.
The above fig explain object creation
car is object.
name and owner is property
bmw and vijay is property value.
The object are globally visible anywhere in document easily accesed object propery value
The above fig objects are not be used var keyword.
How to Access Object?
The object are globally visible anywhere in document easily accesed object propery value
To object are accessed following syntax:
Syntax
object_name.object_property
Types of Javascript Objects:
Also Object can be classified in two ways
1.Built-in Objects
2.User Defined Objects
User defined Objects:
User defined Objects are manually create any object.using new operator. Like following way
var book=new Book( );
var car=new Car( );
var stu=new Student( );
- Create a object use new key word. its used to create an instanceof an object.
- To create an object the new operator is followed by the contructor.
- A constructor is a function that creates and initializes an object
- and User defined objects are using 'This' keyword. The keyword is used to refer to the object has been passed to a fucntion.
The following fig explain
Example:
<html>
<head>
<script type="text/javascript">
function book(t,a)
{
this.title=t;
this.author=a;
}
</script>
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
var b=new book("css","javascript");
document.write(b.title);
document.write(b.author);
</script>
</body>
</html>
Output is:
Built-in Objects:
These objects are already written in javascript. It can accessible anywhere in your document and will work the same way in any browser running in any OS. These object are called Native or Built in Objects.
Many more built in objects available in javascript.
It can use it.
Exmaple:
If you want date value we can use Date() object in following way.
var d=new Date();
var cur_date=d.getDate();
document.write(cur_date);
Date object are already written in javascript. and these object 'd' it can accessed Date object method getDtae().
Javascript Built-in objects
- Number Object
- String Object
- Boolean Objects
- Array Objects
- Date Objects
- Math Objects
- RegExp Objects
- Window Objects
If you learn A-Z javascript you must learn all javascrip objects and methods.
Am post some important objects and methods only in future post....
I hope this post useful to you
Thanks...
No comments:
Post a Comment