If someDiv is going to be used again, then the second option is a lot better. It saves jQuery from ever having to find #someDiv again, and it makes the process of finding things inside someDiv faster.
I'm writing a selector engine at the moment(badly I hasten to add). That's v interesting. I've got a pretty basic after thought of a cache implentation which just caches the results and the selector. I had been wondering whether it was feasible to cache in parts as the search is being processed, but just making good use of the root solves that.
Also interesting ( for me anyway) to see what's returned from $('selector'). A test on a simple list.
Code:
var x = $('ul');
var y = $('li', x);
console.dir(y);
0: li
1: li
.
.
6: li
context : Document
lenght : 7
prevObject : [ ul ]
selector : 'ul li'
I'm starting to see the advantages of returning an array like object.
A quick experiment, which returns a custom array like object.
Code:
function test(selector){
[].push.apply(this, [].slice.call(document.getElementsByTagName(selector)));
}
var y = new test('li');
console.dir(y);
Thanks
RLM
Bookmarks