Calling custom functions from firebug console

早过忘川 提交于 2019-11-30 10:07:24

If showAbout is defined at the global scope, you should be able to write showAbout(); in the console and see the result. If not, then you're probably putting your functions in a scoping function like so:

(function() {
    function showAbout() {
    }
})();

If so, good for you, you've avoided created global variables/functions. But it does mean you can't access those functions from the console, because the console only has access to global scope.

If you want to export any of those so you can use them from the console (perhaps only temporarily, for debugging), you can do that like this:

(function() {
    window.showAbout = showAbout;
    function showAbout() {
    }
})();

That explicitly puts a showAbout property on the global object (window) referencing your function. Then showAbout(); in the console will work.

Your showAbout() probably isn't in the global scope.

It may be wrapped by a $(document).ready() code, and its scope limited to that function.

For testing, you could add beneath...

window.showAbout = showAbout;

You can then call showAbout() from your console, once the function has been defined.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!