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

Result fallback can be a function #1900

Merged
merged 1 commit into from
Oct 22, 2014

Conversation

megawac
Copy link
Collaborator

@megawac megawac commented Oct 22, 2014

Personally I think this is an oversight of #1515 and believe this is a complimentary case -- however, this is easy to get around if you disagree

jashkenas added a commit that referenced this pull request Oct 22, 2014
Result fallback can be a function
@jashkenas jashkenas merged commit 032cd00 into jashkenas:master Oct 22, 2014
@megawac megawac deleted the result-fallback-fn branch October 22, 2014 15:52
@jdalton
Copy link
Contributor

jdalton commented Oct 22, 2014

It wasn't an oversight, it was deliberate. I guess it depends on what phase you consider the default value. When I think of default value I think of the default fully resolved value. After this merge what the user provides as the default could have further resolving done to it.

Side note: This change is breaking and the new behavior should be documented.

@jashkenas
Copy link
Owner

Yes — we shouldn't do this. It makes a lot of sense to use _.result to grab a function, or a fallback function, which this change breaks. Reverted.

@jdalton
Copy link
Contributor

jdalton commented Oct 22, 2014

Thinking on it some more. Normally, without providing a default value, a user has no way of resolving a function property value (the actual function), so maybe it makes sense. It's kind of a wonky case. Imma sip on some coffee and let this marinate.

@megawac
Copy link
Collaborator Author

megawac commented Oct 22, 2014

This came out of a use case in one of my projects. I can give a couple useful examples of why this may be useful

_.result(obj, 'dateCreated', Date.now);
_.result(obj, 'fullName', function() {
      return this.firstName + " " + this.lastName;
});

Again, I'm not married to this being included, but there is some nice sugar that can come from it

@jashkenas
Copy link
Owner

Ah, nice. Sorry for the confusion. Go for it if you like it.

megawac referenced this pull request Oct 22, 2014
megawac pushed a commit to megawac/underscore that referenced this pull request Oct 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants