Is a closure for dereferencing variables useful?

前端 未结 3 1138
孤独总比滥情好
孤独总比滥情好 2020-11-27 21:32

I\'m not sure whether or when it is useful (to improve performance) to dereference variables.

var x = a.b.c.d[some_key].f;
while (loop) {
    do_something_wi         


        
3条回答
  •  隐瞒了意图╮
    2020-11-27 21:35

    If you intend to access a property more than once, consider assigning it to a local variable. However, for modern javascript engines such micro-optimisations will make very little difference, the most important thing thing is to write code that expresses your intent.

提交回复
热议问题