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

Commit 22b9b47

Browse files
Sebastian MüllerIgorMinar
Sebastian Müller
authored andcommitted
refactor(core): use native String.prototype.trim if available
1 parent 5349b20 commit 22b9b47

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Angular.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,20 @@ function isBoolean(value) {
436436
}
437437

438438

439-
function trim(value) {
440-
return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
441-
}
439+
var trim = (function() {
440+
// native trim is way faster: http://jsperf.com/angular-trim-test
441+
// but IE doesn't have it... :-(
442+
// TODO: we should move this into IE/ES5 polyfill
443+
if (!String.prototype.trim) {
444+
return function(value) {
445+
return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
446+
};
447+
}
448+
return function(value) {
449+
return isString(value) ? value.trim() : value;
450+
};
451+
})();
452+
442453

443454
/**
444455
* @ngdoc function

0 commit comments

Comments
 (0)