我可以从外部JavaScript访问控制台命令行API(如来自Firebug或Chrome Inspector控制台的$$和traceAll)吗?

raf*_*uto 2 javascript api console firebug command

是否可以从外部api 访问命令行Api

简单示例:

HTML

  <div id="myDiv"></div>
  <script src="myScript.js"></script>
Run Code Online (Sandbox Code Playgroud)

myScript.js

$$('#myDiv').textContent = 'this will not work';
Run Code Online (Sandbox Code Playgroud)

我不想加载像jQuery或Zepto这样的外部库,因为像这样的seens已经在本地加载了.

Sha*_*ole 5

要回答你的问题,不.但我不认为你真的想要.API可能会更改,从而破坏您的代码.如果您要查找的只是查询选择器.我认为你最好使用MDN上的代码片段.

function $ (selector, el) {
    if (!el) {el = document;}
    return el.querySelector(selector);
}
function $$ (selector, el) {
    if (!el) {el = document;}
    return el.querySelectorAll(selector);
    // Note: the returned object is a NodeList.
    // If you'd like to convert it to a Array for convenience, use this instead:
    // return Array.prototype.slice.call(el.querySelectorAll(selector));
}
alert($('#myID').id);
Run Code Online (Sandbox Code Playgroud)

Document.querySelector