November 2019
Beginner
804 pages
20h 1m
English
Now, you can also implement the TodoList class:
class TodoList {
private _todoList: ReadonlyArray<TodoItem> = [];
constructor(todoList?: TodoItem[]) {
// first we make sure that we have received a valid array
// reference: https://developer.mozilla.org/en- // US/docs/Web/JavaScript/Reference/Global_Objects // /Array/isArray
if(Array.isArray(todoList) && todoList.length) {
this._todoList = this._todoList.concat(todoList);
}
}
get todoList(): ReadonlyArray<TodoItem> {
return this._todoList
}
addTodo(todoItem: TodoItem) {
if(todoItem) {
// the value is "truthy":
// not null, not undefined, not NaN, not an empty string, // not 0, not false this._todoList = this._todoList.concat(todoItem); } } removeTodo(itemId: string) ...Read now
Unlock full access