javascriptpropertiesfield

JavaScript: fields or properties


In every JavaScript tutorial that I have looked at, there is something mentioned about a property of an object, but why do they call it a property?

E.g. Constructor property:

var a = function{this.b}

where b is again called a property.

As far as I know, properties have getters and/or setters, so those should be called fields, shouldn't they?


Solution

  • Some browser vendor have implemented getters/setters for JavaScript properties.

    FF and Webkit has __defineGetter__and __defineSetter__ implemented for DOM objects and get and set for Object's which is outside of the ECMA specification. However both and also IE 8+ has the Object.defineProperty (from the ECMA specification). Read about it here

    As for you original question, I would say that the reason it's called property in JavaScript is that it's a dynamic language and the basic markup uses only properties and local var's. Since everything is bound to a specific scope-hierarchy all you have is different tree-branches on each level. And Douglas Croockford named them properties :)