What is the advantage of initializing multiple javascript variables with the same var keyword?

前端 未结 5 1272
时光取名叫无心
时光取名叫无心 2020-11-30 08:57

When I read javascript code that is clean and written by people who are obviously very good at it, I often see this pattern

var x = some.initialization.metho         


        
5条回答
  •  一整个雨季
    2020-11-30 09:36

    The only real advantage is that it saves a couple of bytes per variable, which in a large JS file can add up; remember that JS files are often sent over the wire.

    Personally I much prefer a single var per line.

提交回复
热议问题