Skip to content

Commit 6b2cf57

Browse files
committed
Merge pull request #1520 from smelnikov/propertyfix
_.property support for null and undefined
2 parents 1f180fb + cd6bb48 commit 6b2cf57

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

test/utility.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
test('property', function() {
3838
var moe = {name : 'moe'};
3939
equal(_.property('name')(moe), 'moe', 'should return the property with the given name');
40+
equal(_.property('name')(null), undefined, 'should return undefined for null values');
41+
equal(_.property('name')(undefined), undefined, 'should return undefined for undefined values');
4042
});
4143

4244
test('random', function() {

underscore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@
11901190

11911191
_.property = function(key) {
11921192
return function(obj) {
1193-
return obj[key];
1193+
return obj == null ? void 0 : obj[key];
11941194
};
11951195
};
11961196

0 commit comments

Comments
 (0)