Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9e3e263

Browse files
yankee42Narretz
authored andcommitted
docs(ngModel): use arguments.length instead of angular.isDefined(newName) to distinguish getter/setter usage
Closes #11604
1 parent 82b2961 commit 9e3e263

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/ng/directive/ngModel.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -990,10 +990,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
990990
var _name = 'Brian';
991991
$scope.user = {
992992
name: function(newName) {
993-
if (angular.isDefined(newName)) {
994-
_name = newName;
995-
}
996-
return _name;
993+
// Note that newName can be undefined for two reasons:
994+
// 1. Because it is called as a getter and thus called with no arguments
995+
// 2. Because the property should actually be set to undefined. This happens e.g. if the
996+
// input is invalid
997+
return arguments.length ? (_name = newName) : _name;
997998
}
998999
};
9991000
}]);
@@ -1205,7 +1206,11 @@ var DEFAULT_REGEXP = /(\s+|^)default(\s+|$)/;
12051206
var _name = 'Brian';
12061207
$scope.user = {
12071208
name: function(newName) {
1208-
return angular.isDefined(newName) ? (_name = newName) : _name;
1209+
// Note that newName can be undefined for two reasons:
1210+
// 1. Because it is called as a getter and thus called with no arguments
1211+
// 2. Because the property should actually be set to undefined. This happens e.g. if the
1212+
// input is invalid
1213+
return arguments.length ? (_name = newName) : _name;
12091214
}
12101215
};
12111216
}]);

0 commit comments

Comments
 (0)