Javascript

Home Load Console Selectors CSS Form Strings If Else Array Reg Exp Date & Time setTimeout JSON Loops Objects Animation Fat Arrow Class Import IIFE undefined Tabulator.js ES6 Event Listeners AJAX Hide Elements Create Elements Checkbox ejs
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

Javascript : ES6

2022-07-18

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()}
});