Skip to content

Commit

Permalink
Revert "Result fallback can be a function"
Browse files Browse the repository at this point in the history
This reverts commit b8a07d1.
  • Loading branch information
jashkenas committed Oct 22, 2014
1 parent 032cd00 commit 40e8517
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
8 changes: 0 additions & 8 deletions test/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,6 @@
strictEqual(_.result(obj, 'a', 'failed'), undefined);
});

test('result fallback can use a function', function() {
var obj = {a: [1, 2, 3]};
strictEqual(_.result(obj, 'b', _.constant(5)), 5);
strictEqual(_.result(obj, 'b', function() {
return this.a;
}), obj.a, 'called with context');
});

test('_.templateSettings.variable', function() {
var s = '<%=data.x%>';
var data = {x: 'x'};
Expand Down
4 changes: 2 additions & 2 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1269,9 +1269,9 @@
_.result = function(object, property, fallback) {
var value = object == null ? void 0 : object[property];
if (value === void 0) {
value = fallback;
return fallback;
}
return _.isFunction(value) ? value.call(object) : value;
return _.isFunction(value) ? object[property]() : value;
};

// Generate a unique integer id (unique within the entire client session).
Expand Down

2 comments on commit 40e8517

@megawac
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats your thought on this @jashkenas, re-revert? Or leave as is. Ping #1900

@jashkenas
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead with a re-revert.

Please sign in to comment.