Geeks With Blogs
Server Error in Application An unhandled exception occurred during the execution of the current web request

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 Posted on Tuesday, August 29, 2006 10:07 AM | Back to top


Comments on this post: Creating Custom Class in JavaScript and adding methods, properties.

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Mahesh Singh | Powered by: GeeksWithBlogs.net