Javascript : ES6
https://www.w3schools.com/js/js_es6.asp
Object Shortcut
var a = obj.a
var b = obj.b
//same as:
let {a,b} = obj
Fat Arrow
// ES5
var a = function(x, y) {
return x * y;
}
// ES6
const a = (x, y) => x * y;
const x = (x, y) => { return x * y };
Getter / Setter
var person = {
firstName: "John",
lastName : "Doe",
get fullName() {
return this.firstName + " " + this.lastName;
}
};
console.log(person)
var a = JSON.stringify(person); // this will strip out the get function automatically
console.log(a)
Setter which does a similar thing..
You can can force the object to have getter like this:
Object.defineProperty(person, "language", {
get : function() { return language },
set : function(value) { language = value.toUpperCase()}
});