Reputation: 1083
I am new to Backbone framework. I have written model and view in backbone. It is giving me the syntax error or as "SyntaxError: function statement requires a name - >initObj: function (height, width) {" while running.
Here is my backbone view code
selectTable = Backbone.View.extend({
render: function() {
var height= 50;
var width= 56;
if (true) {
initObj(chartHeight);
}
initObj: function (height, width) {
console.log("inside initObj");
}
var selector = this.$el.find("select.clg-selection");
selector.html("<option>testtest</option>");
}
});
Here i am just calling "initObj" function but it is giving me the syntax error. Can anyone plese tell me what mistake am i doing here?
Upvotes: 0
Views: 134
Reputation: 7133
initObj
function is not defined inside render
. initObj
is defined as an object property, therefore it should be placed inside of an object:
selectTable = Backbone.View.extend({
render: function() {
var height= 50;
var width= 56;
if (true) {
this.initObj(chartHeight);
}
var selector = this.$el.find("select.clg-selection");
selector.html("<option>testtest</option>");
},
initObj: function (height, width) {
console.log("inside initObj");
}
});
Alternatively, you can define initObj
like:
initObj = function (height, width) {
console.log("inside initObj");
}
and leave it inside render
, but the first is more Backbone-ish.
Upvotes: 1