#30 Get Multiple Properties


Take a look at this code:

That’s a lot of typing, we can refactor this into:

So that’s more readable but now comes the actual tip,  we can set age, firstName, lastName in one call using getProperties and our code would look like this:

Note that getProperties returns an object and we are just using destructuring assignment to set the variables.  so

will create an object myObj with 3 properties named named age, firstName, lastName.

PS: there is also setProperties which you can use to mass assign.

Credits & Links

Ember.Object.getProperties @ http://emberjs.com/api/classes/Ember.Object.html#method_getProperties
Destructuring assignment @ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

Some Love ❤❤❤

If you are enjoying my daily tips please spread the word with this one-click tweet.
If you do NOT like the tips then please reply to this email and let me know.

Published by

Emad Ibrahim

Author of asp .net MVC & TDD, entrepreneur, passionate technologist, programmer and productivity nut. more at http://t.co/oSJXPvzu