O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getters and setters

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?!

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required