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

前端 未结 5 1271
时光取名叫无心
时光取名叫无心 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:21

    Other than the on-wire size, it probably helps interpreter performance as well. From Professional Java Script for Web Developers:

    A single statement can complete multiple operations faster than multiple statements each performing a single operation. The task, then, is to seek out statements that can be combined in order to decrease the execution time of the overall script.

    It went on to recommend declaring variables in a single line.

提交回复
热议问题