I'm struggling to set the instance of a protype. I've got something like this:
function Course() {
// Some stuff
}
Course.prototype.MyMethod = function() {
// Do stuff
}
Now if I create a New Course(), all works fine, however, I'm getting the Courses from JSON. So what I wanted to do is:
data.forEach(function(courseFromJSON) {
courseFromJSON.prototype = Course.prototype;
courseFromJSON.prototype = new Course(); // Doesn't work either
});
But my courses never get the method MyMethod set to them. Neither is setting courseFromJSON.prototype to new Course(). I've been going through Douglas Crockford's video's, but can't seem to get it right. What am I doing wrong?
Thanks.