Two questions about jQuery's inside
Hello everybody,
I'm pretty confident with using jQuery but now I'd like to improve my
understanding of the librarie's code itself.
I sometime see an alternative way of writing portions of code but I'm
pretty sure there is a good reason that it is the way it is... I would
just like to understand.
1. The function hasClass is written this way:
hasClass: function( selector ) {
return !!selector && this.is( "." + selector );
},
Why not simply testing the className against the selector:
return !!selector && (" " + this.className + " ").indexOf(" " +
selector + " ") != -1;
2. In sizzle, many regular expressions for the selectors include:
((?:[\w\u00c0-\uFFFF_-]|\\.)+)
Why is "_" added to the pattern? Isn't it already included in "\w"?
And what is "|\\." for?
Thank you for your attention, I'm pretty sure I will have more of
these questions in the future.