次のコードがあります
define [
"jquery",
"backbone",
"underscore",
"models/days"
], ($, Backbone, _, days) =>
class Calendar extends Backbone.View
el : "#calendar_box"
collection : days
display: =>
@collection.fetch_data
month :8
year :2012
, @render
render: =>
# console.log @collection - gives "undefined"
console.log @ # this returns "Window" instead of "Calendar" - current obj.
# return the calendar object
new Calendar()
これは Coffeescript の BackboneView であり、指定された月と年の日付をカレンダーとして取得するようサーバーに要求します。
Chrome コンソール (GET 要求とその応答) で確認できるため、データは問題なく返されます。
ただし、「render」関数内では、「@」が「Calendar」レベルではなく、グローバル レベルにあるように見えます。
ここで何が起こったのですか?