上QQ阅读APP看书,第一时间看更新
Adding notes
To get started with adding notes, the first thing we'll do is create a variable called notes, and for the moment, we'll set it equal to an empty array, just as in the following, using our square brackets:
var addNote = (title, body) => {
var notes = [];
};
Now that we have the empty array, we can go ahead and make a variable called note, which is the individual note. This will represent the new note:
var addNote = (title, body) => {
var notes = [];
var note = {
}
};
On that note, we'll have the two properties: a title and a body. Now, title can be set equal to the title variable, but, as we know, inside ES6, we can simply remove it when both values are the same; so we'll add title and body as shown here:
var addNote = (title, body) => {
var notes = [];
var note = {
title,
body
};
};
Now we have the note and the notes array.