for novices: in JavaScript we can create the objects with new operator and with object literal .
//with new operator
var myObject = new Object()// creates an empty object;
var myEmployee = new Employee() // creates an Employee object;
//with object literal notation
var myObject = {} // creates an empty object;
var myEmployee = {name:"srinivas"} //created object with name property.
we will use . operator to access the properties and methods on an object.
alert(myEmployee.name) //srinivas
now it's time to create a base class / parent class.(as usual we need to create a function nothing more else).
function Parent(){
this.whoAmI = "parent";
}
we created a function called Parent. remember JavaScript functions are objects. also remember objects may have properties and methods. so our Patent function also an object (don't be scared just imagine every thing is an object). Parent function is having some methods and properties. let's check some important properties and methods.
Properties
- constructor
- arguments // deprecated
- arity
- length
- name
- apply
- call
- toString
//createing a object
var myParent = new Parent();
//whoAmI is called as object's own property
alert(myparent.whoAmI)//parent
//our parent function also an object so we will have a prototype property for this.
alert(typeof(Parent.prototype))//object
No comments:
Post a Comment