diff options
| author | Sebastian Müller | 2013-04-20 19:35:11 +0200 | 
|---|---|---|
| committer | Igor Minar | 2013-07-03 01:42:41 -0700 | 
| commit | 22b9b4757610918456e3486deb514bcc60a08852 (patch) | |
| tree | 7ae9accdc6e6daaf42d4cb4eb803900bcc277168 /src/Angular.js | |
| parent | 5349b20097dc5cdff0216ee219ac5f6e6ef8c219 (diff) | |
| download | angular.js-22b9b4757610918456e3486deb514bcc60a08852.tar.bz2 | |
refactor(core): use native String.prototype.trim if available
Diffstat (limited to 'src/Angular.js')
| -rw-r--r-- | src/Angular.js | 17 | 
1 files changed, 14 insertions, 3 deletions
| diff --git a/src/Angular.js b/src/Angular.js index c1066618..53b53239 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -436,9 +436,20 @@ function isBoolean(value) {  } -function trim(value) { -  return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; -} +var trim = (function() { +  // native trim is way faster: http://jsperf.com/angular-trim-test +  // but IE doesn't have it... :-( +  // TODO: we should move this into IE/ES5 polyfill +  if (!String.prototype.trim) { +    return function(value) { +      return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; +    }; +  } +  return function(value) { +    return isString(value) ? value.trim() : value; +  }; +})(); +  /**   * @ngdoc function | 
