Skip to content

Getters and Setters built in support

Latest
Compare
Choose a tag to compare
@koresar koresar released this 15 Sep 10:20
· 1 commit to master since this release

JavaScript getters and setters are now no different to string or Symbol properties. This means that you can have getters in methods, properties, static properties, configuration, etc.

Example:

const HasFullName = compose({
  properties: {
    firstName: "",
    lastName: ""
  },
  methods: {
    get fullName() {
        return this.firstName + " " + this.lastName;
    },
    set fullName(name) {
        var words = name.toString().split(" ");
        this.firstName = words[0] || "";
        this.lastName = words[1] || "";
    }
  }
});

const developer = HasFullName();
developer.fullName = "Vasyl Boroviak";
console.log(developer.firstName); // "Vasyl"
console.log(developer.lastName); // "Boroviak"  
console.log(developer.fullName); // "Vasyl Boroviak"