May 2018
Intermediate to advanced
190 pages
2h 19m
English
This chapter looks at what’s possible with object literals in JavaScript, especially in the light of recent ECMAScript updates.
The ability to create JavaScript objects using literal notation is powerful. New features introduced from ES2015 (ES6) make object handling even easier in all modern browsers (not IE) and Node.js.
Creating objects in some languages can be expensive in terms of development time and processing power when a class must be declared before anything can be achieved. In JavaScript, it’s easy to create objects on the fly. For example:
// ES5-compatible code var myObject = { prop1: 'hello', prop2: 'world', output: function() { console.log(this.prop1 + ' ' + this.prop2); } ...Read now
Unlock full access