What is the advantage of using get over a regular getter method?

I see this code in MV 



Object.defineProperty(Game_Actor.prototype, 'level', {
get: function() {
return this._level;
},
configurable: true
});


Whereas, I could simply define a method myself that does the same thing


Game_Actor.prototype.level = function() {
return this._level;
};


For me, the obvious difference is in usage


myActor.level // first way
myActor.level() // second way


Is there an advantage to defining getters using the get keyword other than NOT having to type some extra parentheses?
in both way's none 


like I explained on twitter it's just a convention stuff for access a private variable from a another class


both will do the job...although the only difference is when you use configurable


it's totally not the same


when you input configurable to false it's mean ...it's impossible to edit the getter from the external class it's...just here for being read but not edit
Since it's a property of the object, you can access by different means.


On your example you can do also use something like:


myActor['level']


This can be useful when you want to acess the value and have just a string.
Since it's a property of the object, you can access by different means.


On your example you can do also use something like:



myActor['level']


This can be useful when you want to acess the value and have just a string.



You can use strings to get functions as well:


myActor['level']()


Indeed, this code:


myActor.level = function() {
return this._level;
}


Is just the same as this one:


myActor['level'] = function() {
return this._level;
}




Topic: I would say it's just for the sake of code beauty, but reading the mozilla JS documentation on defineProperty shows that it's not just it.


It looks like defineProperty has some additional features like defining a read-only variable automatically with value and using the property when iterating on the object, but it's not really useful if you are just trying to define a normal method as a getter.


__defineGetter__ may be a better choice for using with the average getter function, its effects are the same as if you used defineProperty. It may be deprecated due to code standardization, but if it works... ¯\_(ツ)_/¯
You can use strings to get functions as well:



myActor['level']()

Then I must find out what I did wrong when I tried to use this and it didn't work...  🤔
@Victor Sant Try this:


var myActor = {};
myActor.level = function() {
return 42;
};

console.log(myActor['level']()); // => 42


The only situation I think this code could give you an error is when the function you are calling is undefined...
If you define a getter and setter, you can handle the property just like a normal variable:


Object.defineProperties(Class.prototype, {
attr: {
get: function() { return this._attr; },
set: function(value) { this._attr = value; }
}
});

var cls = new Class();
cls.attr += 3;


/edit: For some reason i always prefer to use "defineProperties" over "defineProperty", even if i only define one of them. I guess it somehow looks cleaner to me and is easily extensible.
When it comes to "properties" vs "functions" I guess I would prefer to not have to "call" a property.


eg: myActor.level vs myActor.level()
(Just joking)Using get over a regular getter method can increase the difficulty for it to be aliased(at least I haven't found an easy and simple way leading to small amount of working codes), which might be advantageous in some cases lol

Original thread: https://forums.rpgmakerweb.com/threads/what-is-the-advantage-of-using-get-over-a-regular-getter-method.55906/