I have a WorkoutExerciseRowView
which extends ExerciseRowView
. The render functions are extremely similar, except the WorkoutExerciseRowView
must add a few parameters to ExerciseRowView
's render. How can I call ExerciseRowView
's render function inside WorkoutExerciseRowView
's render function?
var WorkoutExerciseRowView = ExerciseRowView.extend( {
render : function() {
//return this.constructor.render({ // doesn't work
return this.render({ // doesn't work
workoutExercise : this.model,
exercise : this.model.get("exercise"),
workoutSection : this.model.get("section"),
isEditable : true,
number : this.number,
WorkoutExercise : WorkoutExercise,
WorkoutSection : WorkoutSection
});
}
});
Thanks!
I have a WorkoutExerciseRowView
which extends ExerciseRowView
. The render functions are extremely similar, except the WorkoutExerciseRowView
must add a few parameters to ExerciseRowView
's render. How can I call ExerciseRowView
's render function inside WorkoutExerciseRowView
's render function?
var WorkoutExerciseRowView = ExerciseRowView.extend( {
render : function() {
//return this.constructor.render({ // doesn't work
return this.render({ // doesn't work
workoutExercise : this.model,
exercise : this.model.get("exercise"),
workoutSection : this.model.get("section"),
isEditable : true,
number : this.number,
WorkoutExercise : WorkoutExercise,
WorkoutSection : WorkoutSection
});
}
});
Thanks!
Share Improve this question asked Jun 27, 2012 at 3:47 GarrettGarrett 11.7k20 gold badges86 silver badges129 bronze badges3 Answers
Reset to default 14var WorkoutExerciseRowView = ExerciseRowView.extend( {
render : function() {
return ExerciseRowView.prototype.render.call(this,{
workoutExercise : this.model,
exercise : this.model.get("exercise"),
workoutSection : this.model.get("section"),
isEditable : true,
number : this.number,
WorkoutExercise : WorkoutExercise,
WorkoutSection : WorkoutSection
});
}
});
From Backbone's documentation here: http://backbonejs.org/#Model-extend
Brief aside on super: JavaScript does not provide a simple way to call super — the function of the same name defined higher on the prototype chain. If you override a core function like set, or save, and you want to invoke the parent object's implementation, you'll have to explicitly call it, along these lines:
Backbone.Model.prototype.set.call(this, attributes, options);
You should be able to use
ExerciseRowView.prototype.render.call(this)
This will call the render function from ExerciseRowView with the scope set to this (current model)
this.constructor.__super__.render.call(this,{});