Я сделал класс:
class @GameMap
options : {
'width' : 100,
'height' : 100,
'tileWidth' : 45,
'tileHeight' : 20,
'scale' : 5,
'moveDistance' : 100, #Distance to move with the map controlers
'showErrorMessages' : true,
'zindexDecorElementBase' : 99999,
'zindexGroudElementBase' : 88888
}
lang : {
'errContainerMissing' : "L'élement pour créer la carte n'existe pas"
}
constructor: (@element) ->
this.run()
run: ->
this.loadDatas()
loadDatas: (top,left) ->
$.ajax(
url: "/map/getnewcoord",
data: {
map_width : this.options.width,
map_height : this.options.height,
tile_height : this.options.tileHeight,
tile_width : this.options.tileWidth,
window_large : $('.map-windows').width(),
window_height: $('.map-windows').height(),
top : top ,
left : left
},
success: (data) ->
$.each(data,(index,item) ->
this.createTile(item.posX,item.posY);
)
)
createTile: (m,n) ->
#We are in the tile reference
yDelta = Math.round((options.width ) * options.tileHeight );
console.log('pass')
$ ->
gamemap = new GameMap("#map .block-map")
Но я получил ошибку
this.createTile не является функцией
Это потому, что "this" - это не "this" моего класса, а один из предметов, возвращаемых моим вызовом json
Как я могу сохранить "this" моего класса в функции обратного вызова ajax success?