May 2018
Beginner to intermediate
356 pages
9h 25m
English
One quirky, useful, but somewhat annoying aspect of ES5 JavaScript is its heavy use of callbacks that run asynchronously. You are probably intimately familiar with jQuery code that looks something like this:
$(“#link”).click(function() { var $self = $(this); doSomethingAsync(1000, function(resp) { $self.addClass(“wasFaded”); var processedItems = resp.map(function(item) { return processItem(item); }); return shipItems(processedItems); });});
We're forced to create a variable called $self because the original this context is lost in our inner anonymous function. We also have a lot of boilerplate and difficult-to-read code due to needing to create three separate anonymous functions.
Arrow function syntax is both syntactic sugar ...
Read now
Unlock full access