バックボーンにモデルとビューを作成しました。「SyntaxError: function statement requires a name - >changeClg: function (height, width) {」という構文エラーが表示されます。
selectTable = Backbone.View.extend({
render: function() {
var height= 50;
var width= 56;
if (true) {
changeClg(height,width);
}
changeClg: function (height, width) {
console.log("inside changeClg");
}
var selector = this.$el.find("select.clg-selection");
selector.html("<option></option>");
}
});
しかし、以下のように異なる構文でビューの外側でそのchangeClg関数を宣言すると機能します
selectTable = Backbone.View.extend({
render: function() {
var height= 50;
var width= 56;
if (true) {
changeClg(height,width);
}
var selector = this.$el.find("select.clg-selection");
selector.html("<option></option>");
}
});
changeClg = function (height, width) {
console.log("inside changeClg");
this.$el.find(".clg-dors")[0];
}
実際には、elオブジェクトと他のいくつかのオブジェクトを使用する必要があるため、最初のオプションに移動する必要がありますが、エラーが発生しています。
「changeClg」関数を呼び出すだけですが、構文エラーが発生します。
これら2つの関数宣言の違いは何ですか?
何が問題なのか教えてください。