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

  • SEARCH
  • Home
  • 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 7866669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:28:12+00:00 2026-06-03T00:28:12+00:00

I have the following code for one of my backbone views: class GD.Views.Result extends

  • 0

I have the following code for one of my backbone views:

class GD.Views.Result extends Backbone.View
  template: JST['mobile/templates/result']
  tagName: 'tr'
  className: 'result'
  events:
    'click' : 'showDetail'
    'click #favourite' : 'addFavourite(Favourite)'
    'click #like' : 'addFavourite(Like)'
    'click #dislike' : 'addFavourite(Dislike)'
   render: ->
     $(@el).html(@template(model: @model))
     this
   addFavourite: (type) ->
     event.preventDefault()
     attributes =
       id: @model.id
       type: type
       cluster: @model.cluster
     @collection.create attributes,
     wait: true
     success: @updateIcons
     error: @handleError
   showDetail: ->
     ...
   updateIcons: ->
     ...
   handleError: ->
     ...

And I’m getting this error in my console:

Uncaught Error: Method "addFavourite(Favourite)" does not exist

I don’t really understand why this happens for the AddFavourite method and not the showDetail one – are you not allowed to pass methods which require defined arguments to any event?

Many thanks in advance for 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-06-03T00:28:14+00:00Added an answer on June 3, 2026 at 12:28 am

    As @Derick explained, if the value of an events element is a string, it names a method on your view object, so you can’t specify parameters that way. You need to either (examples are in JS):

    1. Supply just the method name as a string, and then determine the type in the method. E.g.

      events : {
      
        'click #favourite' : 'addFavourite',
      
        'click #like' : 'addFavourite',
      
        'click #dislike' : 'addFavourite'
      
      }
      

      addFavourite : function ( event ) {
      
        event.preventDefault();
      
        var type = event.target.id;
      
      }
      
    2. Suppy a function object (in this example, via a function expression). In this case you could supply a function that calls your generic addFavorite method and passes it the type, e.g.:

      events : {
      
        'click #favourite' : function ( event ) {
      
          this.addFavourite( event, 'favourite' );
      
        },
      
      
        'click #like' : function ( event ) {
      
          this.addFavourite( event, 'like' );
      
        },
      
      
        'click #dislike' : function ( event ) {
      
          this.addFavourite( event, 'dislike' );
      
        }
      
      }
      

      addFavourite : function ( event, type ) {
      
        event.preventDefault();
      
      }
      

    From what I can see in your example, I’d go with option #1.

    Note that this could could be made more dynamic, e.g.:

    events : function () {
    
      var events = {};
    
      var view = this;
    
      [
    
        'favourite',
    
        'like',
    
        'dislike'
    
      ].forEach( function ( type ) {
    
        events[ "click #" + type ] = ( function ( type ) {
    
          return function ( event ) {
    
            view.addFavourite( event, type );
    
          };
    
        } )( type );
    
      };
    
    
      return events;
    
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in one of my Rails 3 application views: <ul>
In Scala IDE I have the following code: package pkg.one object S { class
If I have the following code class One: scope = 'first_scope' class Two: scope
I have the following code in one of my Modules : public class MyModule
I have seen the following code in one of our applications: public class First()
I have the following code in one of my views: <% @videos.each do |i|
I have the following code in one activity: in= new Intent(ThisActivity.this,AnotherActivity.class); imgarr = new
I have the following code in one of my Django templates that I want
One of my backbone view's initialize function contains the following code: $.when(this.broadcasters.fetch(), this.model.fetch(), this.call_types.fetch()).done(
I have the following code in one cpp file which is part of a

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.