Javascript’s new version (EcmaScript 6) has some amazing new features. The one discussed in this post is the new class syntax.
More information can be found here.
// OLD CLASSvarMyObject=function(params){this.p1=params.p1;this.p2=params.p2;};// I will go over the new string interpolation in another postMyObject.prototype.summary=function(){return"p1:"+this.p1+" p2:"+this.p2;};// NEW CLASSclassMyObject{constructor(p1,p2){this.p1=p1;this.p2=p2;}summary(){return"p1:"+this.p1+" p2:"+this.p2;}}
// Getters and SettersclassPerson{constructor(name){this._name=name;}getname(){returnthis._name;}setname(newName){if(newName){this._name=newName;}}}letguy=newPerson("Tom");console.log(guy.name);// GET - Tomguy.name="Steve";// SETconsole.log(guy.name);// GET - Steve// InheritanceclassDevextendsPerson{staticallDevs=[]constructor(name,preferredLang){super(name);this.lang=preferredLang;Dev.allDevs.push(name);}staticnumDevs(){returnDev.allDevs.length;}}