js中apply或call的时间开销

来源:互联网 发布:号码复式软件 编辑:程序博客网 时间:2024/06/11 10:14
console.time('start');function a() {}for (var i=0; i<100000000; i++) {  a();}console.timeEnd('start');
console.time('start');function a() {}for (var i=0; i<100000000; i++) {  a.call();}console.timeEnd('start');
console.time('start');function a() {}for (var i=0; i<100000000; i++) {  a.apply();}console.timeEnd('start');

执行后会发现,用apply或call执行一个函数所需的时间是直接执行的10倍左右,apply和call需要更多的时间开销。

0 0