You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I have some config object that must be initialized. Well, at least some of the properties must be initialized -- some do not.
constinitializableConfig={initialize(data){this.data=data;},geta(){returnthis.data.a;},getb(){returnthis.data.b;}c: "I don't need to be initialized"};
I would like to be able to use the initializableConfig as a default at all times (even before it's initialized). I should be fine to do so as long as I override the properties that must be initialized.
constconfig={a: 'apple',b: 'banana'};constfinalConfig=_.defaults({},config,initializableConfig);// Error! Cannot read property 'a' of undefined
Since config defines a and b, I see no reason why those properties need to be accessed on the initializableConfig. Currently they are and an error is being thrown.
Couldn't _.defaults be optimized to avoid this error?