Click here to Skip to main content
11,935,345 members (58,839 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked

Creating Custom Class in JavaScript and adding methods, properties.

, 29 Aug 2006
Rate this:
Please Sign up or sign in to vote.
This is a brief example of creating custom object in JavaScript.


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.

Now I am making object of MyClass

//Creating Object 
var MyObject = new MyClass (); 

Adding new method and property in "MyClass"

NewObject.prototype = 
    //Adding Method named "MyMethod" 
    MyMethod: function(){alert("My Method");} , 
    //Adding property named "MyProperty" 
    MyProperty: "My Property" 

Calling method and assigning value to property

//Calling Method 

//Assigning Property 
MyObject.MyProperty = "My Property Value changed"; 


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
India India
Around 4 years of programming, application and product development experience in Microsoft Technology (ASP.NET 1.x, ASP.NET 2.0, C#, VB.NET, SQL Server and Oracle). Currently working in Adobe Syatem India, Noida

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
gtankaria18-Jan-13 2:42
membergtankaria18-Jan-13 2:42 
Generalthanks Pin
_Junaid9-Dec-12 6:19
member_Junaid9-Dec-12 6:19 
GeneralMy vote of 1 Pin
kshitij verma10-May-12 20:36
memberkshitij verma10-May-12 20:36 
Suggestionsuggestion Pin
_Junaid9-Dec-12 6:07
member_Junaid9-Dec-12 6:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 29 Aug 2006
Article Copyright 2006 by MaheshSingh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid