0
@@ -201,14 +201,20 @@ test("noConflict", function() {
0
test("trim", function() {
0
-
var nbsp = String.fromCharCode(160);
0
+
var nbsp = String.fromCharCode(160);
0
- equals( jQuery.trim("hello "), "hello", "trailing space" );
0
- equals( jQuery.trim(" hello"), "hello", "leading space" );
0
- equals( jQuery.trim(" hello "), "hello", "space on both sides" );
0
- equals( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " );
0
+ equals( jQuery.trim("hello "), "hello", "trailing space" );
0
+ equals( jQuery.trim(" hello"), "hello", "leading space" );
0
+ equals( jQuery.trim(" hello "), "hello", "space on both sides" );
0
+ equals( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " );
0
+ equals( jQuery.trim(), "", "Nothing in." );
0
+ equals( jQuery.trim( undefined ), "", "Undefined" );
0
+ equals( jQuery.trim( null ), "", "Null" );
0
+ equals( jQuery.trim( 5 ), "5", "Number" );
0
+ equals( jQuery.trim( false ), "false", "Boolean" );
0
test("isPlainObject", function() {
@john : thanks for commendation ;o)
one note ? to avoid all browsers ES5 transitional period pains, I would rather test for trim() existence like so :
Some browsers support and implement String.prototype.trim, but not String.trim, I think ?
Thanks: DBJ
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
@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.
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 :
And this declaration :
Which now obviously should be removed and (tne new and correct)
Should be used, I think ?
Second. String.prototype.trim ---- v.s.--- String.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
Results from http://jsbin.com/ehoje/12
Opera
Safari
Chrome
FireFox
With IE I have not bothered ...
I really think we should not rely on String.trim() , being universaly avaialble
Thanks: DBJ
I hope it is not patronising if I offer this : http://gist.github.com/329172
Thanks : DBJ