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 vendors have implemented different getters/setters for JavaScript properties.

    Firefox and WebKit have __defineGetter__ and __defineSetter__ implemented for DOM (Document Object Model) objects which are outside of the ECMAScript language specification. However, IE 8+ has the Object.defineProperty from the ECMAScript language specification. Read about in this article: Testing getters and setters, and Object.defineProperty.

    As for your original question: I would say that the reason it's called a 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. Plus, Douglas Crockford named them properties :)