A few days ago a friend and I were playing around with the Javascript console in Chrome (using a slightly older version, but this can be repeated in the latest stable build on both OSX and windows) when we assigned a string to the variable $x.
$x = "hello"
but when we echo out the value of $x, we get given the following code in the console:
bound: function (xpath, context)
{
var doc = (context && context.ownerDocument) || inspectedWindow.document;
var result = doc.evaluate(xpath, context || doc, null, XPathResult.ANY_TYPE, null);
switch (result.resultType) {
case XPathResult.NUMBER_TYPE:
return result.numberValue;
case XPathResult.STRING_TYPE:
return result.stringValue;
case XPathResult.BOOLEAN_TYPE:
return result.booleanValue;
default:
var nodes = [];
var node;
while (node = result.iterateNext())
nodes.push(node);
return nodes;
}
}
We got a similar output in stable versions of Safari and Firefox. As far as we can tell, the $x variable is not attached to the global window object.
What is $x, and what's it used for?
A few days ago a friend and I were playing around with the Javascript console in Chrome (using a slightly older version, but this can be repeated in the latest stable build on both OSX and windows) when we assigned a string to the variable $x.
$x = "hello"
but when we echo out the value of $x, we get given the following code in the console:
bound: function (xpath, context)
{
var doc = (context && context.ownerDocument) || inspectedWindow.document;
var result = doc.evaluate(xpath, context || doc, null, XPathResult.ANY_TYPE, null);
switch (result.resultType) {
case XPathResult.NUMBER_TYPE:
return result.numberValue;
case XPathResult.STRING_TYPE:
return result.stringValue;
case XPathResult.BOOLEAN_TYPE:
return result.booleanValue;
default:
var nodes = [];
var node;
while (node = result.iterateNext())
nodes.push(node);
return nodes;
}
}
We got a similar output in stable versions of Safari and Firefox. As far as we can tell, the $x variable is not attached to the global window object.
What is $x, and what's it used for?
Share Improve this question asked May 19, 2012 at 2:52 CodahkCodahk 1,2203 gold badges15 silver badges25 bronze badges2 Answers
Reset to default 15That's an XPath utility function. From the fine Firebug manual:
$x(xpath)
Returns an array of elements that match the given XPath expression.
And from the fine Chrome manual:
$x(xpath)
Returns an array of DOM elements that match the given XPath expression.
The $x
function isn't part of JavaScript itself, it is just a utility that's available in the console. If you try to access $x
outside the console (http://jsfiddle.net/ambiguous/fsewU/), you'll get a ReferenceError unless, of course, you've defined your own $x
somewhere.
Looks to be related to the XPath (XML Path Language)....A helper of sorts...I found a link which may assist you.. http://userscripts.org/topics/26131 Hope that helps..