使用 Backbone 时。View 返回"parent.apply is not a function"错误



考虑这个标记

<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>

这段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();
)};

view(与new view一起)被调用时,Firebug触发这个错误:

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

你知道为什么会这样吗?谢谢。

没关系。

问题在上面js代码的第16行:

var view = new Backbone.View.extend({

it 应该改成:

var view = Backbone.View.extend({

我没有删除这个问题,因为有人可能会发现它有用。我想这是没有计算机科学背景的陷阱。

最新更新