3 ms·
I'd suggest people take a read at Steve Souders' books... Though somewhat dated, they're a bit better and more consistent than tfa. For the most part, write cl
by tracker1 10y ago
I'd suggest people take a read at Steve Souders' books... Though somewhat dated, they're a bit better and more consistent than tfa. For the most part, write clean code... don't optimize until you need to, and have proper profiling/metrics.
As to the examples:
In object access, the output is never written to the innerHTML in the second example. Also, it's unlikely you'll have 10k updates in series.
There's three issues, object chain lookups, which may include prototype crawls in addition to reading/writing innerHTML, as well as string concatentation. 1) Object chain lookups do have some overhead, and with thousands of loops, can make a difference. 2) innerHTML get/set in a loop has the effect of a DOM refresh at each read/write. 3) with the offline version, there is a lot of string concatenation, which has been well optimized in recent JS engines, so not a worry.
With the Custom Objects example, it's abusing the constructor function with a static method attached to the constructor function... this isn't an example of a custom function at all, and I don't know where the author is getting their numbers from.
I'm thinking they did their example wrong.
const MyObject = function() {
return {
create: function() {
console.log('created');
}
};
}
May have been the intended comparison. Either way, if you're creating thousands of objects, you're better off with plain objects and using functional composition, as even object instantiation with the prototype chain has overhead for access.
As to limiting scoping, without ES6 in place (let/const), the only scoping is functions, and even then, you're best off scopign as needed, and letting the runtime advance. The runtime will get better hear, and clean code is better than absolute performance.