Calling custom functions from firebug console

2024/2/27 7:49:17

I created a document that loads a .js document that has some JQuery functions that I have created. I would like to use the firebug console to quickly test the functionality of these functions on my html document. But when I try and call these function in the console I don't get any response.

for example:

  • I have index.html that call my JS:

    <script src="jquery.js" type"text/javascript"></script>
    <script src="myfunctions.js" type="text/javascript"></script>
    
  • Myfuntions.js has the following defined in it:

    function showAbout(){$('div#about').show("slow");$('.navbar #about-button').attr('disabled', true); 
    }
    

The Problem:

When i try to call showAbout or showAbout() from the console on index.html I don't get any changes. However, when I call $('div#about').show("slow"); or $('div#about').show("slow"); from the console directly I get the expected behavior.
What is the proper way to call a user defined function from the console?

Answer

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.

http://en.ppmy.cn/q/41061.html

Related Q&A

Nightmare JS not working

I know the title of the question looks very vague! But thats theres to it.I installed nodejs on my production server, which had phantomjs working properly, then I installed nightmare via npm install ni…

passing query params for aws lambda function

I am trying to set up a Lambda function that will pull query params that are passed into the API Gateway URL that is created. (Sidebar: I am still pretty green when it comes to programming, so please f…

why do we need both iterable and iterator concepts?

In ECMAScript6 an iterator is an object with a next() method that returns an object with two properties: {value, done}. E.g.:function createIterator(ra) {let i = 0;return {next() {if (i < ra.length)…

Checking online status from an iPhone web app

Is there a way to check to see if an iPhone is online from a web app. That is, in mobile Safari, can I check the online status of the device to see if I should try an AJAX call or not.In Firefox/regula…

How much RAM does each character in ECMAScript/JavaScript string consume?

The question is pretty simple: how much RAM in bytes does each character in an ECMAScript/JavaScript string consume?I am going to guess two bytes, since the standard says they are stored as 16-bit uns…

How to send HTML canvas data to server

It seems like there are two ways to send <canvas> data to the server. One is to use canvas.getImageData() to get an array of pixels and their 8-bit color values. The other method is to use canv…

Polymer - Iterating over object in template

According to the polymer docs, an object or array can be iterated over using the repeat statement in a <template>:"expression" can be a simple identifier, a path or a full expression (i…

react set state callback correct way to pass an argument

I am using Reacts setState method, and calling another function when the state has been updated.Is there a preferred approach as to how to call the function that is passed to setState as a callback.Bot…

How to invoke a remote REST service in NiFi

Is it possible to use xmlHttpRequest in NIFI processor to invoke remote rest service? In my case the ExecuteScript processor (using Javascript) cant evaluate XMLHttpRequest; is there any similar solut…

Ember.js value binding with HTML5 file upload

I am not far from it to get the file upload working with Ember-data. But I do not get the value binding right. Below the relevant code.This is the App.jsApp.LandcodeNewRoute = Ember.Route.extend({model…