Classes in Javascript

For all of those who usually code in OO languages, there’s actually a pretty similar approach in JS.

A “class” in JS will have the properties / attributes of the object, along with any methods that might relate to that object. It’s like a template that can be used to create many objects with similar qualities. For example:

function Object(property1,property2){
	this.property1 = property1;
	this.property2 = property2;
         (and so forth)
	this.methodName = function() {
	};
	this.methodName2 = function(){
	};
         (and so forth)
	OR
	methodName: function() {
	}
}

 

And there you go. A neat little packaged class of attributes and methods!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>