0





113
1

using lodash assign method, can I do

_.assign(self, {
            inputContext: createAddonInputContext(),
            currentEmployee: _.first(self.inputContext.employeeList),
        });

the currentEmployee property value calculation depends on inputContext being assigned already. My question is, will this always work, or it can break in some environments i.e. when currentEmployee will be assigned first? In other words, does the order in which properties appear in source object literal guarantee the same order when the value are being evaluated? I'm aware that when we do for...in iteration over javascript object, the order isn not certain. Hence my question.

Question author Dkab | Source

0


1

the currentEmploye property value calculation depends on inputContext being assigned already.

Then you will need to assign them separately:

self.inputContext = createAddonInputContext();
self.currentEmployee = _.first(self.inputContext.employeeList);

will this always work, or it can break in some environments i.e. when currentEmployee will be assigned first?

This never works, it will break in all environments. The object literal and its two property values are evaluated before the call to assign is executed and anything is assigned to self.

Does the order in which properties appear in source object literal guarantee the same order when the value are being evaluated?

Yes, in fact object property values are always evaluated in source order, but this doesn't matter here, the values are inaccessible as properties before the whole object is created.

Answer author Bergi

Ask about this question here!