…and DBJDBJ. More details here: http://forum.jquery.com/topic/faster-jquery-trim Fixes #2279, #4452, and #4835.
- Loading branch information
There are no files selected for viewing
6 comments
on commit 141ad3c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@john : thanks for commendation ;o)
one note ? to avoid all browsers ES5 transitional period pains, I would rather test for trim() existence like so :
var native_trim = "function" === typeof "".trim ;
Some browsers support and implement String.prototype.trim, but not String.trim, I think ?
Thanks: DBJ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also , I seem to remember there is a trim left and/or trim right somewhere in jQuery which now can be changed to use trimLeft ot trimRight , regular expressions ?
Thanks: Dusan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DBJDBJ: I'm not sure what you mean regarding String.prototype.trim - we don't use it, we're only using the native String.trim method, so it's best for us to check to see if that method exists. Also, there is no left/right trim in jQuery - only the one trim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I was to busy for a comprehensive comment.
" .... Also, there is no left/right trim in jQuery - only the one trim....
inside jQuery.extend we have this comment :
// Trim whitespace, otherwise indexOf won't work as expected
And this declaration :
rleadingWhitespace = /^\s+/,
Which now obviously should be removed and (tne new and correct)
trimLeft
Should be used, I think ?
Second. String.prototype.trim ---- v.s.--- String.trim
15.5.4.20 String.prototype.trim ( )
The above is the only legal ES5 , trim() . There is no String.trim() in ES5. This is why I would rather not use it ....
Thanks: DBJ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Results from http://jsbin.com/ehoje/12
Opera
userAgent :Opera/9.80 (Windows NT 6.1; U; en) Presto/2.6.22 Version/10.50
String.trim() → undefined
String.protoype.trim() → function trim() { [native code] }
Safari
userAgent :Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10
String.trim() → undefined
String.protoype.trim() → undefined
Chrome
userAgent :Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.2 Safari/533.2
String.trim() → undefined
String.protoype.trim() → function trim() { [native code] }
FireFox
userAgent :Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6
String.trim() → function trim() { [native code] }
String.protoype.trim() → function trim() { [native code] }
With IE I have not bothered ...
I really think we should not rely on String.trim() , being universaly avaialble
Thanks: DBJ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it is not patronising if I offer this : http://gist.github.com/329172
Thanks : DBJ
Looks like the
deleteExpando
property got removed by accident. Check also bug #7209