Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery source code, classname with linefeeds?

Today I looked at the source code of the jQuery function removeClass:
There is the following line:

className = (" " + elem.className + " ").replace( rclass, " " );

rclass:

rclass = /[\n\t\r]/g,

In the book "JavaScript The Definitve Guide" from David Flanagan, 6th Edition, on page 438 there are the following sentence:

..., so the HTML class attribute is available to JavaScript code using the name className. ... and the class attribute holds a space-separated list of class names.

Why the jQuery coders assume that the class names can also be separated by tabs and line feeds?

like image 856
Wolfgang Adamec Avatar asked Jan 01 '26 01:01

Wolfgang Adamec


1 Answers

Lots of web "developers" know almost nothing about what they are doing and thus write crappy code containing e.g. tab- or linefeed-separated class names.

It is a common principle to "be generous when reading but strict when writing", i.e. accept things that do not really follow $standard but never create such things.

like image 58
ThiefMaster Avatar answered Jan 02 '26 14:01

ThiefMaster



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!