// Artie F830AM section
// April 3, 2015
//
// Goals:
//
// * Practice using inheritance to extend javascript objects.
// * Practice using DOM events:
// - listening for events with addEventListener() and reacting to them
// - bubbling events
//
// Tasks:
//
// * Extend TodoList with a new object called SortedTodoList that always keeps
// todos in sorted order. What about extending it as PersistentTodoList that
// saves objects in localStorage?
//
// * Modify form button event handler to use addEventListener()
//
// * Add an event listener to each todo item displayed in the list so that
// whenever a todo is clicked, it is highlighted in yellow.
//
// * Change it so instead of having multiple event listeners, one for each
// todo, there's just one event listener on the todo list itself, that
// listens for events that bubble up from the todo items.
//
// * Add an event handler to the text input on the form so that hitting "enter"
// will add the todo item.
//
// * Add an event handler so that you can move a TODO up or down in the list
// by hitting the up/down arrow key.
//----------------------------------------
// Creates a Todo object that holds data about a single "todo" item
var Todo = function(name, priority) {
this.name = name; // string
this.priority = priority; // number 0-3
this.priorityStrings = ["High Priority", "Medium Priority", "Low Priority"];
};
Todo.prototype.asString = function() {
return "Todo: " + this.name + " (" + this.getPriorityString() +")";
};
Todo.prototype.getPriorityString = function() {
return this.priorityStrings[this.priority].toLowerCase();
};
//----------------------------------------
// Creates a TodoList object that contains Todo objects.
var TodoList = function() {
this.items = [];
};
TodoList.prototype.getItems = function() {
return this.items;
};
TodoList.prototype.addItem = function(item) {
this.items.push(item);
};
// SortedTodoList *inherits* from TodoList. It...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.