Skip to content
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

Anonymous(?) function passed to keys().value() given a name #29

Open
Selbosh opened this issue Jan 26, 2018 · 1 comment
Open

Anonymous(?) function passed to keys().value() given a name #29

Selbosh opened this issue Jan 26, 2018 · 1 comment
Assignees
Labels
next book update To incorporate on the next update to the book

Comments

@Selbosh
Copy link

Selbosh commented Jan 26, 2018

In Chapter 16, it's not clear why the anonymous function passed to stack.keys(keys).value() is given a name. Line 117 reads:

https://github.com/alignedleft/d3-book/blob/4cbba7c74ebd29e6a07ec25150bf0ddb6e108112/chapter_16/01_initial_chart.html#L117

The full block is

//Tell stack function where to find the keys
stack.keys(keys)
    .value(function value(d, key) {
        return d[key].sales;
    });

But this is functionally equivalent (having checked the console.log()) to

stack.keys(keys)
    .value(function (d, key) {
        return d[key].sales;
    });

(And of course in ES6:)

stack.keys(keys)
    .value((d, key) => d[key].sales);

So I'm not sure if this is a mistake, an inconsistency in style, or something subtle that I am missing (but in which case should be documented.)

This appears on page 336 of the 2nd edition of the book.

@scotthmurray
Copy link
Owner

@Selbosh hey, great catch. I think it's just a (rare!) stylistic inconsistency. I will accept the fact that you noticed it as evidence that I was highly consistent throughout the book otherwise. See, you were really writing in with a compliment! 😄

Thanks for catching this. I'm going to leave this open, as I'd like to amend this with the next update to the book (though the code will remain unchanged for now).

@scotthmurray scotthmurray self-assigned this Jul 2, 2018
@scotthmurray scotthmurray added the next book update To incorporate on the next update to the book label Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next book update To incorporate on the next update to the book
Projects
None yet
Development

No branches or pull requests

2 participants