I'm going through the peepcode jQuery example (https://peepcode.com/products/jquery) and I chose to update all the dependencies.
Not surprisingly, I ran into an issue concerning the difference between string literals and String objects in javascript (great discussion here: Why are there two kinds of JavaScript strings?)
One problem I'm hitting is that jQuery.each converts string literals to String objects, which the jQueryUI method removeClass does not handle properly. Here is a code snippet that fixes the issue.
I'd like to know if the bug is in jQuery.each incorrectly converting string literals to String objects or should removeClass assume that it could get either a string literal or a string object.
Update: I just realized that here's another workaround: Strings in array are no longer strings after jQuery.each()
Here's the code:
jQuery.fn.extend({
taskStates:["task-empty", "task-x", "task-apostrophe", "task-dash"],
resetTaskStateClassNames: function() {
var elements = this;
// Commented code breaks as "this" becomes the String object not the literal
// and removeClass does not check for String Object
// jQuery.each(jQuery.fn.taskStates, function(){
// elements.removeClass(this); // this is the taskState
// })
jQuery.fn.taskStates.forEach( function(ts) {
elements.removeClass(ts);
});
return this;
},