0

I have a question about userscripts. Is it faster to have this in before or after of the main function initiateFlasher?

if (typeof unsafeWindow !== 'undefined' && unsafeWindow.jQuery) {
    initiateFlasher(unsafeWindow.jQuery);
} else {
    function addScript(callback) {
        var script = document.createElement('script');
        script.text = '(' + callback.toString() + ')();';
        document.body.appendChild(script);
    }
    addScript(initiateFlasher);
}


function initiateFlasher(arg) {}
Anteus
  • 21
  • 4

1 Answers1

0

The speed difference will be negligible. But it's better form to define initiateFlasher() first. (When in doubt, use jslint.com.)

This is a good habit to get into because, even though a function declaration will work on most browsers before or after, function expressions or function constructors will not.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Thanks! I saw that in Safari console it complained about initateFlasher() wasn't defined first. – Anteus Sep 24 '11 at 16:52