Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6321023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:04:38+00:00 2026-05-24T16:04:38+00:00

I come from a C++/Java background, but I’m having problems getting the syntax right

  • 0

I come from a C++/Java background, but I’m having problems getting the syntax right on this javascript. This is what I was trying to accomplish. I want a base class TemplateBaseView which inherits from Backbone.View. The TemplateBaseView overrides the initialize and render function from the Backbone.View. I am also using underscore.js. Here is a brief attempts, any help would be appreciated.

  function TemplateBase(){}
  TemplateBase.prototype.render = function(){ ... }
  TemplateBase.prototype.initialize = function(){ ... }
  _.extend( TemplateBase , Backbone.View );

And I essentially want to do something like this,

var HeaderView = TemplateBase({ template: _.template($("#header_template").html())};

which would create a Backbone.View object essentially with the default render and initialize function and the template attribute specified.

Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:04:39+00:00Added an answer on May 24, 2026 at 4:04 pm

    You want to use the built in extend from backbone.

    var TemplateBase = Backbone.View.extend({
      'this': 'is',
      'a': 'class'
    });
    
    var HeaderView = new TemplateBase;
    

    A couple things. You can refer to TemplateBase as a ‘class’ but there’s really no such thing in javascript, that’s just a useful name for people coming from class based languages. It’s technically a prototype.

    Next: Remember to use new when you create an instance of TemplateBase, otherwise you’re just invoking a function and setting your object to whatever that function returns, rather than an instance of that prototype.

    Finally, just a convention, most people would capitalize their ‘classes’ but not their instances. So I could change HeaderView to headerView

    edit

    After reading your question again, maybe you want HeaderView to be a class? In which case:

    var HeaderView = TemplateView.extend({
      template: _.template( $("#header_template").html())
    });
    
    var headerInstance = new HeaderView;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from a java background and there's something I could do in Java
I come from a Java background, and I see a lot of people say
I come from an Actionscript3 background and this is my first time writing any
I come from an Eclipse/Vim background, and I've just started using Emacs for the
I'm taking a C# class right now and I'm trying to find out the
I am new to both JAVA and Google App Engine. My Interest in Java
I have been using Python for about a year now, coming from a mostly
I've read quite a bit about initialization of static class variables in c++ and
I've been using Object as a way to have a generic associative array (map/dictionary)
The question is in two parts. The first is conceptual. The next looks at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.