Javascript - Getter and Setter (Accessor)

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard > Javascript - Object

1 - About

object accessor in Javascript. Since ECMAScript 5.

3 - Example

var foo = {
    foo: "foo",
    get bar(){ return this.foo; },
    set bar( value ){ this.foo = this.foo + value; }
};
console.log(foo.bar);
foo.bar = "bar";
console.log(foo.bar);

Advertising
web/javascript/es/object/accessor.txt · Last modified: 2019/02/16 17:40 by gerardnico