Showing posts with label this keyword. Show all posts
Showing posts with label this keyword. Show all posts

Wednesday, 27 April 2016

JavaScript Objects

A javaScript object is an entity having state and behavior (properties and method).
JavaScript is an object-based language. Everything is an object in JavaScript.
JavaScript is template based not class based. Here, we don't create class to get the object. But, we direct create objects.

Creating Objects in JavaScript
There are 3 ways to create objects.

  1. By object literal
  2. By creating instance of Object directly (using new keyword)
  3. By using an object constructor (using new keyword)
1) JavaScript Object by object literal

Syntax:
object={property1:value1,property2:value2.....propertyN:valueN}  

2)By creating instance of object 
Syntax:
var objectname=new Object();  

3) By using an Object constructor
The this keyword refers to the current object.

Example:
<script> 
function student(id,name,age){
this.id=id;
this.name=name;
this.age=age;
}
st=new student(103,"Vimal Jaiswal",12);
 
document.write(st.id+" "+st.name+" "+st.age);
</script> 


Monday, 20 January 2014

this KEYWORD IN JAVA

this  is a keyword in Java. Which can be used inside method or constructor of  class. It(this) works as a reference to current object whose method or constructor is being invoked. this keyword can be used to refer any member of current object from within an instance method or a constructor.