JSFiddle - React, Tailwind, and code Playground
by infralabs
JavaScript
/*
Comparison of calling object's method ways.
*/
var obj = {
subObject: {
fn: function() {
return 'some data';
}
}
}
console.time('calling through');
for (let i = 0; i < 10000000; i++) {
obj.subObject.fn();
}
console.timeEnd('calling through');
console.time('calling once');
var fn = obj.subObject.fn;
for (let i = 0; i < 10000000; i++) {
fn();
}
console.timeEnd('calling once');