Asked By: Anonymous
I am stuck with familiar issue but I am unable to resolve it on my own. So Please help me to get rid out from this issue.
My view code:
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()));
}
});
My rendering code :
$(document).ready(function() {
var LayoutView= new LayoutView({
el:'#wrapper',
model:{}
});
});
My exception:
Uncaught TypeError: LayoutView is not a constructor
Solution
Answered By: Anonymous
Your code should be:
$(document).ready(function() {
var layoutView= new LayoutView({
//--^---this
el:'#wrapper',
model:{}
});
});
Because the local variable declaration with same name is hiding the original constructor.