Using inheritance in meteor.js

inheritance, javascript, meteor, model-view-controller

Solution

I think the short answer is no, but here's a longer answer:

One thing I've done to share functionality among templates is to define an object of helpers, and then assign it to multiple templates, like so:

var helpers = {
    displayName: function() {
        return Meteor.user().profile.name;
    },
};

Template.header.helpers(helpers);
Template.content.helpers(helpers);

var events = {
    'click #me': function(event, template) {
        // handle event
    },
    'click #you': function(event, template) {
        // handle event
    },
};

Template.header.events(events);
Template.content.events(events);

It's not inheritance, exactly, but it does enable you to share functionality between templates.

If you want all templates to have access to a helper, you can define a global helper like so (see https://github.com/meteor/meteor/wiki/Handlebars):

Handlebars.registerHelper('displayName',function(){return Meteor.user().profile.name;});

Problem

I've been hoping to use inheritance in Meteor, but I couldn't find anything about it in the documentation or on Stack Overflow. Is it possible to have templates inheriting properties and methods from another abstract template, or class?

Original source

Related problems