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:
1. make the property access a static query. i.e.
var result = object.property
OR
2. make the property access a dynamic query, i.e.
var result = object["property"]
The difference it makes to me is that for the first case (static query case) i will have to generate separate code for each property access. whereas in the second case (dynamic query case) i can reuse the same function for every property.
I can decide if i know does this makes any difference in performance?
is obj.property faster or obj["property"]?
May be this also depends on the engine which will be used to interpret javascript, so i must mention that I will be using Rhino as my javascript engine.
So please throw some light on this issue.
Thanks,
Regards,
VImal
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.