Today's exercise was to improve the render method in TodoMVC. The problem with the render method was that it did more than just render the view. It also stored data to local storage. Here's a look at the method:
Read MoreMastering Javascript Fundamentals: AccountingJS Internal Helper Methods (Part 2): defaults
Summary
The defaults() function allows you to pass in two objects and apply the properties from the second object to the first one where those properties don't already exist on the first object.
It does this by enumerating through each property on the second object and checking to see if that property exists on the first object. If the property doesn't exist, it applies that property to the first object.
This is a way to only need to define "custom" properties when creating a new object, and then setting all the "standard" options to the defaults set in another "default" object.
Read on to see how this all works in detail.
Read MoreMastering Javascript Fundamentals: Scopes, locals, closures, globals
Summary:
Functions can always remember the variables they could see at creation.
They can see variables defined inside the function.
They can see variables defined in enclosing functions.