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

Commit 7b7be34

Browse files
Sebastian Müllerbtford
Sebastian Müller
authored andcommitted
refactor(core): use native String.prototype.trim if available
1 parent 751c77f commit 7b7be34

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
@@ -442,9 +442,20 @@ function isBoolean(value) {
442442
}
443443

444444

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

449460
/**
450461
* @ngdoc function

0 commit comments

Comments
 (0)