Introduction
This is a brief example of creating custom object in JavaScript.
Creating Class
For creating class in javascript first we have to create the function whose name should be same as class. This function is called as constructer.
For example I want to create the class Named MyClass so function name should be MyClass
function MyClass()
{
alert("New Object Created");
}
We can also add the argumnets in this function.
Now I am making object of MyClass
var MyObject = new MyClass ();
Adding new method and property in "MyClass"
NewObject.prototype =
{
MyMethod: function(){alert("My Method");} ,
MyProperty: "My Property"
}
Calling method and assigning value to property
MyObject.MyMethod();
MyObject.MyProperty = "My Property Value changed";