17
Apr

getters / setters in JavaScript classes

function myClass(){
this.name;
}

myClass.prototype.setName = function(Name){
this.name = Name;
}

myClass.prototype.getName = function(){
return this.name;
}

var x = new myClass();
x.setName(“Jackychan Adventures”)

console.log(x.getName())

output:
——–

Jackychan Adventures