Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery core commit code for trim method

Tags:

jquery

Can someone help me understand this commit

What is \u00A0 ?

like image 682
Roger Avatar asked Sep 14 '26 16:09

Roger


1 Answers

The code strips trailing and leading space characters in addition to non breaking spaces, \u00A0 is the unicode point/code/number/alias for the non breaking space. You can pop up Firebug and type it out.

>>> '\u00A0'
" "

Further information about this character:

http://www.fileformat.info/info/unicode/char/00a0/index.htm

Edit: I just tried this code in Firebug, which checks for any matches from the generated non breaking space and it matched:

javascript:alert( String.fromCharCode(160).match(/\s/) )

However, upon doing this in IE6 it returns null, so IE is most likely the reason for this update.

Update #2 - it looks like the removal of the caret makes this inconsistent with the previous version, because it removes not just leading and trailing spaces but spaces anywhere.

r = /(\s|\u00A0)+|(\s|\u00A0)+$/g;

s = '  wh  at'

s = s.replace( r, '' )

Outputs

"what"
like image 196
meder omuraliev Avatar answered Sep 16 '26 05:09

meder omuraliev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!