Explain me DefineProperties

Hey guys! 

I wanted to work on something special for a game and I was curious because I create a base for my game but I was unsure the use of DefineProperties ....I know it's meant to short the job?

so in simple of what I saw in Game_BattlerBase ...it's seem usefull for define's a lots of states properties.

SO I want to know...how do you use these code? do I  have to use this._something 

or I could just do "something"?

here the code I have for the moment.

// Ho My Maid! Basefunction HMM_Base(){this.initialize.apply(this,arguments);} HMM_Base.prototype.constructor = HMM_Base;Object.defineProperties(HMM_Base.prototype, {// Define maid strenght. strengh: { get: function() { return this._strengh; }, configurable: true },// Define maid speed. speed: { get: function(){return this._speed; }, configurable: true },// Define }); HMM_Base.prototype.initialize = function() { this.clear(); }; HMM_Base.prototype.clear = function() { this._honor = 0; this._strengh = 0; this._hunger = 0; this._energy = 0; this._courage = 0; this._speed = 0; this._dexterity = 0; };I would like if you people can explain me how to properly use defineProperties thanks 🙂
its similar to rubies attr_accessor methods, if that helps 🙂
I can see why although it's not really explain me how to use them properly :c

I mean after I define them how I am supposed to use them?
function MyEpicObject(){this.initialize.apply(this,arguments);}MyEpicObject.prototype.constructor = MyEpicObject;Object.defineProperties(MyEpicObject.prototype, { attr1: { get: function(){ return this._somePrivateAttribute1; }, configurable: true }, attr2: { get: function(){ return this._somePrivateAttribute2; }, configurable: true },});var myEpicObject = new MyEpicObject();myEpicObject.attr1myEpicObject.attr2Helpful? 🙂
I see! so now example how I use them INSIDE the current classes it's define? (myEpicObject)
Well, you just have to have access to the object like you would any other object. The only difference between calling a 'property' and a function, is for properties, you don't need the () at the end of its name. You still have to have any scope access to the object you would normally have. 🙂
so I inside the defined classes I can still use 

attr1 = something

or I have to use 

this._privatevalue = something

? 
Using inside the class, you should always access it via 'this._privatevalue'. If you wanted your class to be able to change the value from outside the class, you would include a 'set' property value as well as a 'get', and then you define the setter function. 🙂

Actually, not really.. You could argue that it would be best to always call the attr1 from within the object, cayuse then it reduces the amount of lines you need to change, if you wanted to change the name of the private variable or something. 🙂 )
I see....I guess I get the idea lol...

EDIT : actually........No I just don't get it..how to use it sorry :/
Object.defineProperties(MyEpicObject.prototype, { attr1: { // GET function get: function getFunk(){ return this._somePrivateAttribute1; }, // SET function set: function setFunk(i){return this._somePrivateAttribute1 = i; }, configurable: true },});Pretty easy really, you just have to manually define both the getter and setter funciton, like, in ruby, it would look like this...

def attribute return @attributeenddef attribute=(newValue) return @attribute = newValueendOr, the much quicker ruby version of the exact same code...

attr_accessor :attributeIts all the same 🙂
I see now I understand 🙂

Original thread: https://forums.rpgmakerweb.com/threads/explain-me-defineproperties.52693/