Prototype Question

24 views
Skip to first unread message

Max Nathaniel Ho

unread,
Sep 15, 2015, 1:31:54 AM9/15/15
to cs164-discuss
Hi all,

Once again, thank you to the staff at Harvard CS Department for this enriching course. 

I was watching JavaScript, Part 1, and I found certain parts difficult to comprehend, especially the parts regarding the Prototype methods.


I have one main question. 

var CS = function() { Course.apply(this, arguments); };
// Create a temporary object so we can get an instance // of the course and

var temp = function() {}
temp
.prototype = Course.prototype;

// The CS "prototype chain" now has an
CS
.prototype = new temp();
CS
.prototype.department = 'Computer Science';


Based on the above lines of code, what is the reason for creating a new temp.prototype object and assigning it to CS.prototype versus simply creating a new course.prototype object and assigning it to CS.prototype, since both we are inheriting the prototypes from the Course object. 


Sorry but Tim's explanation wasn't clear.

Thank you.



Reply all
Reply to author
Forward
0 new messages