Server Error in Application

An unhandled exception occurred during the execution of the current web request
posts - 60, comments - 76, trackbacks - 54

My Links

News

My Bookmarks

Archives

Post Categories

ASP.NET

Creating Custom Class in JavaScript and adding methods, properties.

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

Print | posted on Tuesday, August 29, 2006 10:07 AM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 1 and type the answer here:

Powered by: