This is what I don't understand, and reading about it is over my head. I need a very dumbed down version to ever understand it:
Creating prototypal inheritance: Previously, you have created generic custom object for task that had a number of attributes (task name, description etc). Now, you will demonstrate your knowledge of prototypal inheritance by creating a top level task object and different types of tasks based on category. For example, you may have a task category of Grocery that will have different attributes than a task category of Education. However, both types of tasks will need to inherit some generic attributes and methods from the parent task object.
I also don't really understand how to store tasks as objects or why you would need to do this in the context of a task list, and how you would do it. I think this would be the first step before prototypal inheritance? Thank you to anyone who has the time to explain.
I'm currently failing my JavaScript Advanced class, so any tips are appreciated!
$(document).ready(function () {
var task = {
name: "",
description: "",
status: "",
eta: "",
priority: "",
owner: "",
initiate() {
console.log("Starting Task");
this.status = "IN PROGRESS";
console.log(this);
},
complete() {
console.log("Ending Task");
this.status = "COMPLETED";
console.log(this);
}
};
var education = {
grade: "",
studentName: "",
subjects: [],
__proto__: task
};
var grocery = {
items: [],
budget: "",
spend: "",
__proto__: task
};
education.grade = "10th";
education.studentName = "Diana";
education.subjects = ["Science", "History"];
education.name = "Complete Assignments";
education.description = "Useful for better grades";
education.initiate();
education.complete();
});
Console for the above code is :
> "Starting Task"
> [object Object]
> "Ending Task"
> [object Object]
As you can see education and grocery are new objects which are now extending the original "task" object. the two new objects are now basically inheriting all the attributes and functions of the "task".
CodePen : https://codepen.io/pranaynailwal/pen/GRrKqQV?editors=1111