From 22b9b4757610918456e3486deb514bcc60a08852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Sat, 20 Apr 2013 19:35:11 +0200 Subject: [PATCH] refactor(core): use native String.prototype.trim if available --- src/Angular.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index c10666188dcb..53b532393955 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