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!
The Backbone. js view extend method is used to extend the Backbone. js view class to create a custom view. Syntax: Backbone.
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
BackboneJS allows developing of applications and the frontend in a much easier way by using JavaScript functions. BackboneJS provides various building blocks such as models, views, events, routers and collections for assembling the client side web applications.
var 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With