有点难以理解coffeescript。为什么这是 set_position 函数中的窗口对象?
window.App = {}
$ ->
driver = new Driver if ($('#drivers_become').length >= 1)
window.App.driver = driver
class Driver
constructor: ->
@get_position()
get_position: ->
if navigator.geolocation
navigator.geolocation.getCurrentPosition(@set_position)
set_position: (pos) ->
# this refers to window object in this case. why?
@latitude = pos.coords.latitude
@longitude = pos.coords.longitude
get_latitude: ->
@latitude
get_longitude: ->
@longitude
在这种情况下,get_latitude 和 get_longitude 返回 undefined。