function Person(firstName, lastName) {
this.fullName = function () {
return `${firstName} ${lastName}`;
};
}
Handlebars has a few steps:
Why do we use AJAX: whenever we need data that isn't included in our raw HTML file:
Added page on the Gitbook
map
- Return a new array of values where each value is changed by the callback
var simpsons = [{first: 'Homer'}, {first: 'Marge'}, {first: 'Bart'}, {first: 'Lisa'}];
var output = simpsons.map(function(familyMember) {
return familyMember.first;
}); // ['Homer', 'Marge', 'Bart', 'Lisa'];
filter
- Filter down array forEach element where the callback returns true
var simpsons = [{first: 'Homer'}, {first: 'Marge'}, {first: 'Bart'}, {first: 'Lisa'}];
var output = simpsons.filter(function(familyMember) { return familyMember.indexOf('i') > -1; }); // [{first: 'Lisa'}]
reduce
- work towards a single value that represents the array (sum, multiples, etc)
https://github.com/tiy-lr-fee-2015-June/lesson-5.2
In today's lab, we made a new version of our podcast site.
This time we pulled out a render
function so that we can render an array of podcast.
Then we added an input and listened for user input using $('input').on('input')
, then we had our callback use Array.prototype.filter
and filtered out results based on our search term!
For tonight's homework, we'll be working through something called a Koan.
This is a set of exercises using tests that will guide you through some of the fundamentals of Javascript along with the array functions we covered today.
For each test, you will be changing the value of FILL_ME_IN
to make the test pass (turn green).