title: Using JS Class Setter & getter along with inline functions
body: <p>I'm currently trying to setup a class where the property is an array of another object (define by another class).</p>
  <p>I'm using the set/get to manage the values. I also initialize them in the constructor.</p>
  <p>what I want to achieve is adding inline function to this same property to make life easier overall. However, I feel like I'm using the wrong approach here.</p>
  <pre><code>class _MainObject {
      constructor(){
          this._property = [];
          this.property= {
              add(value, index){
                  if (value.constructor.name !== '_SubObject'){
                      return;
                  }
  
                  this._property.splice(index, 0, value);
              },
              remove(value){
                  if (value.constructor.name !== '_SubObject'){
                      return;
                  }
  
                  const index = this._property.findIndex((pId) =&gt; pId === value.id);
                  this._property.splice(index, 1);
              }
          };
      }
  
      set property(value){
          if (Array.isArray(value)){
              value.map((el) =&gt; {
                  if (el.constructor.name !== '_SubObject') return;
              });
              this._property = value;
          }
          //Tried a bunch of stuff here to assign the default object from above on the first initialization.
      }
      get property(){
          return this._property;
      }
  }
  </code></pre>
  <p>Whenever the constructor initialize the property, it trigger the &quot;set&quot; and won't assign the functions to 'property' itself.</p>
  <p>I want the actual data in obj._property but fetch by calling obj.property. I also want to be able to call obj.property.add().</p>
  <p>This must be doable in some way and I just don't know how.</p>
  <p>Ideally, I want to use ES5+ semantic.</p>
  <p>Thanks in advance for any help provided.</p>