2011-09-24 61 views
0

我有一个关于用户脚本的问题。在主函数initiateFlasher之前或之后是否更快?性能userscript注入代码

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) {} 

回答

0

速度差异可以忽略不计。 但是最好先定义initiateFlasher()。 (如有疑问,请jslint.com。)

这是一个很好的习惯进入,因为即使一个函数声明将大多数浏览器上工作之前或之后,function expressions or function constructors will not

+0

谢谢!我看到它在Safari控制台中抱怨initateFlasher()没有先定义。 – Anteus