Javascript property access speed: difference var.property vs. var[“property”]?

后端 未结 3 1219
野的像风
野的像风 2021-01-18 12:35

I have a very basic JavaScript question.

I am writing a program which will generate JavaScript code. for accessing a property of a variable i have two choices:

3条回答
  •  半阙折子戏
    2021-01-18 12:47

    There are no static properties in Javascript, only dynamic property accessing exists.

    Properties are always queried in the same way regardless of what syntax you put in your source code file.

    Use jshint to recommend good source code conventions for your JS files:

    http://jshint.com/

    Dot notation is always recommended. Use quotation mark notation only if your Javascript property has not id which passes in JS syntax.

提交回复
热议问题