Here's an idea for the future:

Multiple/alternative selector schemes (ie. CSS3, XPath1, XPath2)
and compilation of selectors into native Javascript.


jQuery.<selector-scheme> = {
   select: function(query, context, params) {
     var fn;
     if (typeof query == 'string') {
       fn = (this.cache[query] === undefined)
          ? this.compile(query) : this.cache[query];
     } else if (typeof query == 'function') {
       fn = query;
     }
     return fn(context, params);
   },
   compile: function(query) {
     return this.cache[query] = eval(this.toJS(query));
   },
   toJS: function(query) {
     // Compiles query into native javascript function:
     return '(function(context, params) { ... })';
   },
   cache: {},

   ... additional utility functions for toJS() ...
}

Where <selector-scheme> could be:
CSS3
XPath1/XPath2
Hybrid (current jQuery selectors)


'params' provides a way of passing extra vars to a selector,
as in XPath:

   $('[EMAIL PROTECTED]', document, {inputId: 'blah'})


Then the developer can choose their preferred
selector scheme:

   $ = jQuery.CSS3.select;

or:

   (function($) {
     ...
   })(jQuery.XPath2.select)


Javascript packing/optimising tools could be extended to take advantage
of the .toJS function and precompile selectors into native Javascript.

NOTE: This has just come to me, I thought I'd note it down and send it
for discussion before I forget - not really had chance to think too much
about it or the practicalities of it.

I hope it sparks some ideas, Any thoughts?

- Mark.

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to