Click here to Skip to main content
13,559,528 members
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 29 Aug 2006

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 1:42
membergtankaria18-Jan-13 1:42 

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.

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