aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Müller2013-04-20 19:35:11 +0200
committerBrian Ford2013-08-12 16:23:38 -0700
commit7b7be341b6081792130223e220ca80002c32b290 (patch)
treeea6e123e837d3e1376d159b505ef70851f0afe08 /src
parent751c77f87b34389c5b85a23c71080d367c42d31b (diff)
downloadangular.js-7b7be341b6081792130223e220ca80002c32b290.tar.bz2
refactor(core): use native String.prototype.trim if available
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 362bc09b..467af4ce 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -442,9 +442,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