17
Apr

working with Javascript class

Following code snippet demonstrates usage of class in JavaScript:
—————————————————————–

var MyClass = function() {
this.name = ‘Shinchan’;
this.type = ‘cartoon’;
};

MyClass.prototype.setName = function(name) {
this.name = name;
return this;
};

MyClass.prototype.setType = function(type) {
this.type = type;
return this;
};

MyClass.prototype.save = function() {
console.log(
‘saving ‘ + this.name + ‘, the ‘ +
this.type + ‘ ‘ + ‘ Hero…’
);
};

new MyClass().setName(“Sheetal”).setType(“Cartoon character”).save();

Output:
——

saving Sheetal, the Cartoon character Hero…