calculate an object property based on the value of another property of the same object
If you do not want to have to call isActive as a function, you can use a getter.


const obj = {
  name: "X Æ A-12 Musk",
  get isActive () {
    return this.name.length > 4;
  },
};

console.log(obj.isActive);




I need to find out the value of "name" inside on the obj object. How can I find it without function invocation?
I wanna use just obj.isActive not obj.isActive()
let obj = {
  name: "X Æ A-12 Musk",
  isActive: function () {
    return this.name.length > 4;
  },
};

// and after a while I need to check if is active:

console.log(obj);

// { 
//   name: 'X Æ A-12 Musk',
//   isActive: [Function: isActive]  <--------- NOT COOL ! 
// }



If use an IFEE:
let obj = {
  name: "X Æ A-12 Musk",
  isActive: (function () {
    return this.name.length > 4;
  })(),
};

I get:
return this.name.length > 4;
                ^
TypeError: Cannot read properties of undefined (reading 'length') 

