-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chapter 4: Abstraction Example wrong logic #190
Comments
"property of an object" vs "property of the store"... these are the same thing, I'm not sure what distinction you're trying to make?
You're correct, I accidentally reversed the logic here. Not that it really matters all that much, since this whole section of code is what not to do. But it's something that could be cleaner. The simple fix would just be: function isUndefined(val) { return val === undefined; }
function isPropDefined(val,obj,prop) {
return !isUndefined( obj[prop] );
} It's something I'll take a look at for next revisions/editions of the book. |
You are right. The thing is that in the original example you check if the name of the event is undefined, but in the last example you check if the key in the store is undefined, so this is the wrong logic I'm trying to fix. const events = {
'js-conf': {
name: 'js-conf'
}
};
trackEvent({});
console.log(events);
// Example 1: { 'js-conf': { name: 'js-conf' } }
// Example 2: { 'js-conf': { name: 'js-conf' }, undefined: {} } |
Oh, I see. OK, yes, I'll fix that too. |
If you want I could make a pull request on that. |
No thanks. I won't be making changes to the book since it's been in print for almost 2 years now. These changes will be addressed when/if I release a second edition. |
In the last abstraction example (when you took the abstraction too far) the logic in the code is wrong compared with the original example shown earlier. So if this is intentionally, please disregard the comment below and just add clarification in the description of the example.
First mistake
The code above is ok to check if a property of an object is undefined, but here you change the logic of the previous example and check if a property of the store is undefined.
Original logic:
Proposal:
Just change the name of the function and wrap the function in another one which accepts the property to be checked against undefined. This will lead to the need of invoking the function with an argument name in this case.
Now we could change the invokation of checkFn to be with only one argument.
The text was updated successfully, but these errors were encountered: