What type of object / property is the prototype of getter and setter?

Reading John Resig's article on Javascript getters and setters I see a structure in which I am not familiar with Javascript:

Field.prototype = {
    get value(){
        return this._value;
    },
    set value(val){
        this._value = val;
    }
};

The prototype is the same object as many others, but the parts received and assigned here seem unfamiliar. What name are they called? They are not like the typical properties of an object (following the syntax "key":"value"), and they are not exactly like standard functions.

Is it just syntactic sugar that turns the JS engine into something more recognizable?

Update:

The real problem of my question is this: since the { foo(){} }syntax is invalid, what makes it valid with the getor operator set?{ get foo(){} }

+4
1

, , , @RGraham (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/get), , .

, "get" "set" , -.

, , :

  • , .
  • .
  • -, -, , , .

() , , .

, , , -.

- , , . , ...

var Field = {
    get value(){
        return this._value;
    },
    set value(val){
        this._value = val + 1;
    }
};

Field.value = 100

console.log( Field.value );

:

101

: http://jsfiddle.net/zV8Kf/1/

, " { get foo(){} } ?" :

:

  • ,
  • , 'foo'

, foo undefined

:

http://jsfiddle.net/VHAhA/

get foo: function ( , , : " - ", :

{ foo: function foo() {} }

{ foo(){} }, JavaScript, - , , .

+4

All Articles