How to Create a Class in Javascript

There are so many ways to create a class in JavaScript, but this one is the easiest and simplest for me.

var Person = {
init: function(nameParam) {
this.name = nameParam;
},
printName: function() {
console.log('Name: '+ this.name);
}
};

var me = Object.create(Person);  // <== one level of inheritance

me.init('Edesa');
me.printName();

 

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPrint this pageEmail this to someone

Leave a Reply

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