Here's the code I'm working with at the moment:
Object.defineProperty(String.prototype, "testy", {
get: function() {
return this.string;
},
set: function(string) {
this.string = string;
}
});
console.log("tessfef3t".testy());
Before I would've used String.prototype.testy = function {}
, however I've been told that using something similar to the the code above is the better way to do it. I'm not sure how that is meant to work but I haven't got that code to work yet.
Could someone show me how to correctly do what I'm doing?
Thanks