0

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 ?

2
  • What exactly are you asking about? The const keyword or the destructuring assignment? Commented May 15, 2018 at 10:01
  • It's just a way of getting 'getOwner' value from 'Ember' object Commented May 15, 2018 at 10:03

2 Answers 2

1

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); }

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.