In my JS component class, I have the following code at the top;
const { getOwner } = Ember; What exactly does it mean ? Is the purpose to avoid code repetition ?
This is a new feature of JS present in ES6. This is known as object destructure.
If you have an object like this.
const obj = { name: 'Stack Overflow' }; const { name } = obj; console.log(name); You can take a reference -> Here for Destructure
And yeah about the const keyword. The const keyword is used to declare a constant variable which is going to be same for the whole
and for const -> Here
try{ const a = 10; a =12; }catch(e){ console.log(e); } Is the purpose to avoid code repetition.
I don't really think so.
It is just a destructing assignment to assign Ember object's getOwner property to variable getOwner in your code. And const is there to make sure it is not overwritten by some other assignment
constkeyword or the destructuring assignment?