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.

[code]

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();

[/code]

 

Leave a Reply