Reputation: 2394
In coffescript, I want to call a class method from a jquery callback, how do I access the class's scope? this.loadImage(currentIndex) doesnt work
class ImageCarousel
currentIndex = 0
jsonPath = "json/images.json"
images = null
constructor: () ->
this.loadJson()
loadJson: () ->
$.ajax jsonPath,
success : (data, status, xhr) ->
console.log("yea "+data)
this.images = data.images
this.loadImage(currentIndex)
error : (xhr, status, err) ->
console.log("nah "+err)
complete : (xhr, status) ->
console.log("comp")
loadImage:(@index) ->
console.log("load image "+@index)
Upvotes: 1
Views: 1269