CONTEXT LOGIC

CONTEXT LOGIC


My question/comment : What is a CONTEXT LOGIC in jQ ? I think it
should be : dom node inside which is the result set to be found?
The dom node inside which is jQuery to use the selector given. Default
is document.
If I read it right , jQ doc says that context type can be (only?) dom
node or jQuery instance. So I expected that if I give context as a
string it will be takens as selector for the jQuery, which will
eventualy spill out a single dome node to be used as a context. And
that
way one can speed up her code, because querying inside the known dom
element must be quicker than querying inside the whole document, each
time. finding on the branch is faster that finding from the root of
the tree.
But it seems that if string is given as a context , the selector get's
it as a prefix and context is a dom document ? So :
$("[name]", "#people") is the same as saying $("#people[name]",
document ) , because jQ makes it into this.
While one might expect the above to be translated to : $("[name]",
document.getElementById("people") ) , which could considerably speed
up the slection ...
A quick sample I have made (quickly) is here: http://jsbin.com/avowu/edit
// context is correctly reported by jQ
$("[name]", document.getElementById("people")).formula( log ) ;
// this.context is reported by jQ as HTMLDocument ?
// this.selector is prefixed with context
$("[name]", "#people") ;
Is this "by design" ? Maybe jQ does this :
1 :: jQuery("#people").find("[name]")
2 :: this.context = "#people" + "[name]"
So that plugins can see the context which actually was used ? So the
line :
$("[name]", "#people")
after all IS actually making things faster ? And I am (or I was)
confused with the value of this.context and this.selector, available
to me inside a plugin ? But then I think I can;t be right here,
because it would be much better to have the selector and context, as
originaly
given by the user :
1 :: this.context = "#people" ; this.selector = "[name]" ;
2 :: jQuery(context).find(selector)
After this plugins will see the original selector and context.
Provided my assumptions are correct.