When reading this http://www.html5rocks.com/en/tutorials/speed/v8/, it makes sense that changing the type of the variable at runtime makes the browser work more intensively than maintaining their consistency.
Does this mean that this is not a good idea:
var x = { alpha: null, bravo: null, charlie: null, delta: null, echo: null } x.alpha = {a:1, b:true} x.bravo = 13 x.charlie = true x.delta = [1,2,3] x.echo = 'abc'
Because here the types begin as null, then change to an object, int, boolean arrary.
And for simplicity, these types never change.
Or is it more efficient:
var x = { alpha: {}, bravo: 0, charlie: false, delta: [], echo: '' } x.alpha = {a:1, b:true} x.bravo = 13 x.charlie = true x.delta = [1,2,3] x.echo = 'abc'
I can understand how types change, since the number in the array is not a good idea. How about going from zero to type once at runtime?
In books and blogs that I read, they mostly talk to define variables with a zero value (as opposed to undefined), when the values ββare known only at runtime. With the value of the face, this seems to be incorrect, since the definition with their empty type allows avoiding the type change.
performance javascript google-chrome
Brian mcginity
source share