JavaScript – Use a variable for a function call

Sometimes you want to pass a function around from script to script as a string containing the function name (well maybe not, but I have some legacy code that does require this)

So if you have a function called doSomething() and you want to call it from another page, but you’ve passed it like so:

<script type="text/javascript">
function startSequence()
    var nextFunction = 'doSomething';
    return nextFunction;

So what I’m saying is the function will be placed into the Window object, so you can call it :


And it obviously extends to the window.opener object.

I’m sure there are better ways, but this is handy to know I think.

Viewing events attached to elements via JavaScript

If like myself, you often attach functions to elements using jQuery, for example:

$('.btnName').live('click', function() {
    //do something

There is a nice little browser extension that will show all the elements on the page with a little bubble outlining the attached events/functions.

It is written by Allan Jardine, and you can get it from