I came across the array notation in JavaScript, and I wondered which way would be faster or better to write. I think the second version is harder to read, but are there any benefits of it ? Or does somebody use this way of calling the methods? Or is there no difference between those regarding their speed?
-
$('#myContainer')['addClass']("active"); -
$('#myContainer').addClass("active");
I am used to doing it the second way, but is the first way faster or are there any other benefits of using the first version?
JSPerf: http://jsperf.com/brackets-vs-dot-notation
According to the perf, the bracket notation is faster in some browsers.
This is a kind of micro-optimalisation which you should avoid. Choose the notation which feels the most comfortable.