jQuery "ajax" function is kind of monolithic... difficult to adapt/improve
I've got a project I've released which is a drop-in replacement (100%
API compatible with) of the browser's native XHR object. It
implements full cross-browser functionality, but with the familiar
API. The primary design reasoning for this was that I wanted my
project to be able to be easily plugged-in/adapted to the major JS
frameworks (jQuery, Dojo, Prototype, etc), since they all use XHR
somewhere inside them.
My problem has been that the other frameworks provide a small utility
function which they use to generate the XHR instance that they then
use. So, adapting to use my object is easy, I just have to override
the appropriate function and have it instantiate mine instead of the
native one. This has worked beautifully with Dojo, ExtJS, Prototype,
and YUI.
However, to the best of my inspection abilities, it appears that
jQuery has no such separate function for the XHR object instantiation,
but is instead inside of a much bigger, more complex function called
"ajax".
So, my adapt approach wouldn't work here unless I was prepared to re-
invent nearly all of the logic inside that function, which is a really
bad idea in my thinking.
I guess I could take the source of the function, convert it to a
string dynamically, regex replace, and then re-eval... but that is
INCREDIBLY ugly to do.
So, my question is, does anyone have any thoughts on if jQuery could
be extended this way? Or am I going to have to re-invent the "ajax"
wheel to get my object working inside jQuery?
Is there any chance that jQuery dev would consider moving the XHR
instantiation out into another "factory" function, like the other
frameworks do, so it could more easily be altered?