the new addition of jqXHR seems be a great feature, but the name of itself seems odd to me. I feel jQuery design has focus lots on semantics, names "live", "die", "when", these are good examples, instead of using "jqLive", "jqDie", "jqWhen". So I think jqXHR should be just named as "xhr", it is much easier to communicate amount developers.
///parameter shifting if ( !prototype ) { prototype = base; base = $.Widget; } ...}
The semantics here is to support optional parameter base, you can do $.widget(name, prototype) or $.widget(name, base, prototype) the idea is good, but what is odd is that the position of optional parameter is in the middle of function, but not the last one. We should support calls like $.widget(name, prototype) or $.widget(name, prototype, base)
$.widget = function( name, prototype, base) { //.. if (!base) { base = $.Widget; } //.. }
But since this interface has been used already, refactory is almost impossible, as it change the semantics and will break other code. My idea is that optional parameter should be the last one, is this good or bad? Thanks
I know that every language has its own culture, the culture of JavaScript is definitely unique. I am a big fan of jQuery, but I have mixed feeling in the implementation of jQuery core. The passed in parameters get reused and overloaded for semantics in many places, is it part of javascript culture. I know this might help to improve performance, but I don't know the actual performance gain, but the cost of maintenance will definitely increase. I have changed dataAttr function in data module of jQuery core, and it is for my personal understanding. The code passed the unit test in firefox 3.6. Do you think it is better or worse? Thanks
function tryGetDataFromHtml5DataAttr(elem, key, data) { //if data is has value already //or elem is not element node if (data !== undefined || elem.nodeType !== 1) { return data; } // If nothing was found internally, try to fetch any // data from the HTML5 data-* attribute var attributeValue = elem.getAttribute("data-" + key); if (typeof attributeValue !== "string") { return undefined; }
I know that jQuery.cache object is used to implement the data api. I feel it is little in secure to expose to outside, for example, external script could easily break our app, by using jQuery.cache = null
Should it be encapsulated in side the closure, so that it would not be temper.