【发布时间】:2017-03-09 08:00:12
【问题描述】:
class MyClass
defaultOptions:
url: '/photos.json'
constructor: (@element, @options) ->
@photos = []
@init()
addPhotos: (photo) ->
@photos.push photo
request: ->
$.getJSON(this.defaultOptions.url).done((data) ->
@addPhotos data
return
).fail (jqxhr, textStatus, error) ->
err = textStatus + ', ' + error
console.log 'Request Failed: ' + err
return
init: ->
@request()
当我从控制台运行此命令时
var myClass = new MyClass("#myElement")
我收到此错误
TypeError: this.addPhotos is not a function. (In 'this.addPhotos(data)', 'this.addPhotos' is undefined)
知道为什么我无法在请求方法中调用 addPhotos 方法,我该如何调用它?
【问题讨论】:
-
看看这里的胖箭头是怎么处理的stackoverflow.com/questions/13184209/…
标签: coffeescript