r/javascript • • Oct 09 '18

Writing Lighter, Faster JavaScript Functions

https://medium.com/p/c631739af349
40 Upvotes

23 comments sorted by

View all comments

16

u/yojimbo_beta Mostly backend Oct 09 '18
function isStooge(name) {   
    const STOOGES = ['Larry', 'Curly', 'Moe'];   
    return STOOGES.includes(name);
};

90% sure the engine will tag that array for re-use.

In fact, wasn't the cause of that recent iOS 12 array reversal issue that mutated array literals were being re-used inappropriately?

5

u/gsnedders Oct 09 '18

In fact, wasn't the cause of that recent iOS 12 array reversal issue that mutated array literals were being re-used inappropriately?

Ding-ding-ding! Yes. JSC does copy-on-write of arrays and objects consisting purely of literals.