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()
{
//This function is same as a constructer
alert("New Object Created");
}
We can also add the argumnets in this function.
Adding new method and property in “MyClass”
NewObject.prototype =
{
//Addign Method named “MyMethod”
MyMethod: function(){alert("My Method");} ,
//Adding property named “MyProperty”
MyProperty: "My Property"
}
Now I am making object of MyClass
//Creating Object
var MyObject = new MyClass ();
Calling method and assigning value to property
//Calling Method
MyObject.MyMethod();
//Assigning Property
MyObject.MyProperty = "My Property Value changed";
ASP.NET Interview Questions |
C# Interview Questions |
.NET Interview Questions |
Dot Net Interview Questions |
VB.NET Interview Questions |
Oracle Interview Questions