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

correct _.times example in index.html #2670

Merged
merged 1 commit into from
May 23, 2017
Merged

Conversation

dragmove
Copy link
Contributor

hello :) I've discovered issue of example _.times method in index.html file.

I just have changed

_(3).times(function(n){ genie.grantWishNumber(n); });

to

_.times(3, function(n){ genie.grantWishNumber(n); });
.

Always thanks to underscore. :)

@dragmove dragmove changed the title Docs: correct _.times example change correct _.times example in index.html May 20, 2017
@dragmove dragmove changed the title change correct _.times example in index.html correct _.times example in index.html May 20, 2017
@coveralls
Copy link

coveralls commented May 20, 2017

Coverage Status

Coverage increased (+1.6%) to 96.763% when pulling a5382ed on dragmove:master into d4f52aa on jashkenas:master.

@captbaritone
Copy link
Collaborator

This is a valid, although under-documented syntax in Underscore. See: http://underscorejs.org/#oop.

@craigmichaelmartin
Copy link
Contributor

Sure, and this syntax is even called out before the example. That said, why introduce complexity to someone trying to understand the method? An example of using just the function at hand seems more helpful.

@captbaritone
Copy link
Collaborator

captbaritone commented May 22, 2017 via email

@captbaritone captbaritone reopened this May 22, 2017
@coveralls
Copy link

coveralls commented May 22, 2017

Coverage Status

Coverage increased (+1.6%) to 96.763% when pulling a5382ed on dragmove:master into d4f52aa on jashkenas:master.

@craigmichaelmartin
Copy link
Contributor

My two cents: what is described as the "functional style" is the canonical form; it uses the methods according to the signature they actually have. The OOP style offers a convenient wrapper which just applies the wrapped value to the canonical form. Given that, I would think all examples (except the OOP one) should use the functional style.

If we want to think of OOP as an equally valid syntax, we should add more examples to the docs. If we want to deprioritize it, we should scrub all examples outside of the OOP-specific docs.

Currently the docs treat the functional style as the canonical form - not because of the examples but because each function (eg, each) is exposed as a property on _ (_.each(list, iteratee, [context])) and not as a instance method on an _ instance (see the function header http://underscorejs.org/#each). I think demonstrating the function using an instance of _ with the function under consideration put on the prototype as a mixin is inconsistent with how the function is presented, and introduces unnecessary complexity to understand the example.

One downside of deprioritizing is that when you do come across OOP code in your code base, it can be extremely hard to figure out what's going on.

For sure. I think if we go this route (and actually even if we don't) we should surface the OOP section when querying for _( and ( on the underscore site.

@captbaritone
Copy link
Collaborator

@craigmichaelmartin Agreed. Let's do it. I'll merge this and followup with a PR to remove the note about OOP style. Improve searching to account for for _( and ( will take a little bit of shuffling. @dragmove, is that something you would like to look into? The code lives in docs/main.js.

@captbaritone captbaritone merged commit 67e43b6 into jashkenas:master May 23, 2017
captbaritone added a commit to captbaritone/underscore that referenced this pull request May 23, 2017
captbaritone added a commit that referenced this pull request May 11, 2018
Remove note made obsolete by #2670
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants