Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: fields or properties

In every JavaScript tutorial that I have looked 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 property. As far as I know properties have getter and/or setter, so those one should be called field, shouldn't they?

like image 357
bliof Avatar asked Feb 02 '11 08:02

bliof


1 Answers

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 :)

like image 74
fredrik Avatar answered Oct 16 '22 16:10

fredrik