使用Backbone.View时,返回"parent.apply不是函数"错误

eag*_*eal 30 backbone.js

考虑这个标记

<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>
Run Code Online (Sandbox Code Playgroud)

而这段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();
)};
Run Code Online (Sandbox Code Playgroud)

view调用(with new view)时,Firebug会触发此错误:

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

为什么会发生这种情况的任何想法?谢谢.

eag*_*eal 88

没关系.

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

var view = new Backbone.View.extend({
Run Code Online (Sandbox Code Playgroud)

应该是:

var view = Backbone.View.extend({
Run Code Online (Sandbox Code Playgroud)

我没有删除这个问题,因为有人可能觉得它很有用.我想,不是来自CS背景的陷阱.

  • 我犯了同样的错误!谷歌直接带我到这篇文章;)谢谢. (3认同)
  • 这也节省了我的一天.谢谢. (3认同)
  • 是的 这是一个愚蠢的错误,但是我做到了,yayyy:D感谢您发布此信息! (2认同)
  • 我已经花了一个小时搜索错误...请不要删除它:D (2认同)