July 2017
Intermediate to advanced
300 pages
5h 43m
English
Getters and setters were added back in ES5.1. In ES2015, it was extended for computed property names and goes hand in hand with a short method notation:
class Robot { get nickname(){ return "But you have to prove first that you belong to the Rebel Alliance!"; } set nickname( nickname ){ throw new Error( "Seriously?!" ); } }; const robot = new Robot(); console.log( robot.nickname ); robot.nickname = "trashcan";
$ node es6.jsBut you have to prove first that you belong to the Rebel Alliance!Error: Seriously?!
Read now
Unlock full access