Chrome中使用的变量$ x是什么? [英] What is the variable $x used for in Chrome?

查看:1251
本文介绍了Chrome中使用的变量$ x是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我和一个朋友在Chrome浏览器中使用Javascript控制台(使用稍旧的版本,但是可以在OSX和Windows的最新稳定版本中重复),当我们为字符串分配一个字符串变量$ x。

  $ x =hello

但是当我们回显$ x的值时,我们会在控制台中获得以下代码:

  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;
默认值:
var nodes = [];
var node;
while(node = result.iterateNext())
nodes.push(node);
返回节点;




$ b我们在稳定版本的Safari中获得了类似的输出, Firefox浏览器。据我们所知,$ x变量没有附加到全局窗口对象。



什么是$ x,它用于什么?

解决方案

这是一个XPath实用程序功能。从精美的Firebug手册


$ x(xpath)

返回


并从 fine Chrome manual
$ b


$ x(xpath)

返回与给定的XPath表达式匹配的DOM元素数组。




$ x 函数不是JavaScript本身的一部分,它只是一个在控制台中可用的实用程序。如果您尝试在控制台外访问 $ x http: //jsfiddle.net/ambiguous/fsewU/ ),你会得到一个ReferenceError,除非你已经在某处定义了你自己的 $ x

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?

解决方案

That'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.

这篇关于Chrome中使用的变量$ x是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆