Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using Backbone.View a "parent.apply is not a function" error is returned

Tags:

backbone.js

Consider this markup

<div id="controls" class="controls">   <a href="#">Home</a> -    <a href="#/get">get</a> -    <a href="#/new">new</a>   <input type="text" val="" id="input"> </div> 

And this piece of javascript:

$(document).ready(function() {   "use strict";    // this is used on my code as root.App,   // but the code was omitted here for clarity purposes   var root = this,   undefined;    var controller = Backbone.Controller.extend({      routes : {       // static     },   });    var view = new Backbone.View.extend({     el : $('#controls'),     events : {       'click a' : 'updateOnEnter'     },      updateOnEnter : function(el) {       alert('sss');       return this;     },      initialize : function() {       _.bindAll(this, 'render', 'updateOnEnter');     },      render : function() {        return this;     }   });    new view;   new controller;   Backbone.history.start(); )}; 

When view is called (with new view), Firebug fires this error:

parent.apply is not a function error backbone.js (line 1043): child = function(){ return parent.apply(this, arguments); };  

Any ideas to why this is happening? Thanks.

like image 378
eagleal Avatar asked Apr 22 '11 22:04

eagleal


1 Answers

Never mind.

The problem is on line 16 of the above js code:

var view = new Backbone.View.extend({ 

it should instead be:

var view = Backbone.View.extend({ 

I'm not deleting this question since somebody may find it useful. The pitfalls of not coming from a CS background, I guess.

like image 198
eagleal Avatar answered Oct 23 '22 02:10

eagleal