Tag: es6everyday

  • ES6 Everyday: The End

    We made it! (Huge thanks to the ES6 Compatibility Table and the Mozilla Developer Network (MDN), which I relied on heavily in putting together this series of posts) Over the past two months, we’ve broken the seemingly overwhelming ECMAScript 6 standard into digestible little pieces: Introduction Default Parameter Values Spread Operator Rest Parameters Destructuring Binary […]

  • ES6 Everyday: Reflect

    Yesterday, we talked about the new Proxy object in ES6, a construct that enables meta-programming in JavaScript. While we’re on that topic, let’s look at a new built-in object within ES6: Reflect. Reflect is a global object with a slew of static methods to use in JavaScript meta-programming. Let’s check out a few. The Reflect.get() […]

  • ES6 Everyday: Proxies

    ES6 introduces a new meta-programming object called the Proxy. First, say you have an anonymous object: var user = { name: “Logan”, role: “Admin” }; Now let’s say we wanted to inject some logic when trying to access user.name; a Proxy lets us do this. First, we create a handler: var handler = { get: […]

  • ES6 Everyday: Modules

    For a lot of longtime JavaScript developers (and especially those from the Node world), this is long overdue: yes, ES6 has modules. When writing a JavaScript-heavy application, things always seem to start simply: function displayCampingSites() { // …logic to display camping sites } And then things get a little more complex: function getCampingSites() { // […]

  • ES6 Everyday: Shorthand Properties and Methods

    Take a look at this: var name = “Logan”; var age = 27; var person = { name: name, age: age }; console.log(person.name); // Logan Something about name: name and age: age seems so silly and redundant, right? ES6 agrees and provides us with a shorthand property syntax: var name = “Logan”; var age = […]

  • ES6 Everyday: Computed Properties

    You’re familiar with creating an object literal in JavaScript: var animal = { name: “Horse”, species: “E. Ferus” }; console.log(animal.name); // Horse In this example, name and species are properties on the animal object. You’ll notice that “name” and “species” must be statically written. In other words, we can’t specify dynamic property names. To do […]

  • ES6 Everyday: New Object Methods

    Hey, you want some new object methods? ES6’s got ’em: Object.is Determines if two values are the same value. MDN has a pretty stellar criteria for whether or not two values are the “same value”; it essentially boils down to a more complete implementation of the strict equality operator (===): // Similarities Between Object.is and […]

  • ES6 Everyday: Typed Arrays

    “Typed arrays” provide an efficient method for accessing and manipulating data. The motivation behind this is to provide a construct to handle all of the raw binary data that will start flowing into JavaScript (audio data, video data, etc.). “Typed arrays” actually encompasses two separate classes: ArrayBuffer and DataView. The ArrayBuffer contains our data and […]

  • ES6 Everyday: New Array Methods

    ES6 brings a whole slew of new Array methods. Let’s check them out: Array.from Creates a new array from an array-like object (has a length property and indexed elements) or an iterable object: var menu = new Map(); menu.set(“Hamburger”, 5.50); menu.set(“Soda”, 2.50); menu.set(“Fries”, 3.00); var menuArray = Array.from(menu); console.log(menuArray[1][0]); // Soda console.log(menuArray[1][1]); // 2.5 You […]

  • ES6 Everyday: WeakSets

    If you’ve been following along, you might have expected this one: Map, Set, WeakMap, and now (drumroll) WeakSet. Like Map versus WeakMap, WeakSet is very similar to Set, except for a few key differences: WeakSet can only store objects (no primitive values) WeakSet holds values “weakly” and does not prevent garbage collection on values WeakSet […]