diff options
| author | Igor Minar | 2011-03-27 15:58:24 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-03-30 15:24:03 -0700 |
| commit | 96a1df192a167e6e34988af687693506f4efd1d1 (patch) | |
| tree | df4603b0e1043500aaecc5c51a257371ad9f2732 /src/Angular.js | |
| parent | 89c25fe7136e49faa88a4b2a1922c822a5470313 (diff) | |
| download | angular.js-96a1df192a167e6e34988af687693506f4efd1d1.tar.bz2 | |
extend size() to take ownPropsOnly param
- extend size() to take size(obj, ownPropsOnly)
- add specs for size()
- update docs to mention string support
- use size() in ng:repeat
including the hasOwnProp check for all object doesn't create
significant perf penalty:
http://jsperf.com/dedicated-code-branch-for-hasownprop
Diffstat (limited to 'src/Angular.js')
| -rw-r--r-- | src/Angular.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Angular.js b/src/Angular.js index c815d5fc..f4cb9b51 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -461,12 +461,14 @@ function map(obj, iterator, context) { * @function * * @description - * Determines the number of elements in an array or number of properties of an object. + * Determines the number of elements in an array, number of properties of an object or string + * length. * * Note: this function is used to augment the Object type in angular expressions. See * {@link angular.Object} for more info. * - * @param {Object|Array} obj Object or array to inspect. + * @param {Object|Array|string} obj Object, array or string to inspect. + * @param {boolean} [ownPropsOnly=false] Count only "own" properties in an object * @returns {number} The size of `obj` or `0` if `obj` is neither an object or an array. * * @example @@ -483,14 +485,15 @@ function map(obj, iterator, context) { * </doc:scenario> * </doc:example> */ -function size(obj) { +function size(obj, ownPropsOnly) { var size = 0, key; if (obj) { if (isNumber(obj.length)) { return obj.length; } else if (isObject(obj)){ for (key in obj) - size++; + if (!ownPropsOnly || obj.hasOwnProperty(key)) + size++; } } return size; |
