Uncaught TypeError: View is not a constructor

Uncaught TypeError: View is not a constructor

我遇到了熟悉的问题,但我无法自行解决。所以请帮我摆脱这个问题。

我的查看代码:

var LayoutView = Backbone.View.extend({
  initialize: function() {
    var self = this;
    $.get('resources/html/layout.html', function(data) {
      self.template = _.template(data);
      self.render();
    });
  },
  render: function() {
    var self = this;
    $(self.el).html(self.template(self.model.toJSON()));
  }
});

我的渲染代码:

$(document).ready(function() {
    var LayoutView= new LayoutView({
        el:'#wrapper',
        model:{}
    });
});

我的例外情况:

Uncaught TypeError: LayoutView is not a constructor

您的代码应该是:

$(document).ready(function() {
   var layoutView= new LayoutView({
   //--^---this
    el:'#wrapper',
    model:{}
   });
});

因为同名局部变量声明隐藏了原始构造函数