我在这里做错了什么?我在我的回调函数中使用了fat arrows =>,但是当代码到达cb.onEndElement并调用@returner时,我会得到一个null对象异常。那么为什么@returner不存在?
class Parser
constructor: () ->
@returner = (data) ->
searchParser: new xml.SaxParser (cb) =>
cb.onStartElementNS (elem, attrs, prefix, url, ns) =>
if elem is "results" then @results = []
else if elem is "title" then @curr = "title"
else @curr = "none"
cb.onCdata (cdata) =>
if @curr is "title" then @book.title = cdata
cb.onEndElementNS (elem, prefix, url) =>
@results.push @book if elem is "book"
cb.onEndDocument =>
@returner @results
search: (str, callback) ->
@returner = callback
@searchParser.parseString str
p = new Parser
p.search "somexml", (data) ->
console.log JSON.stringify data