Stopping setInterval in coffeescript
问题 How can I stop the setInterval in my script ? Alert working, clearInterval not, and there isn't any error in console. order = start_poll: -> interval = setInterval(@request, 60000) stop_polling: -> clearInterval order.start_poll() alert ('expired') request: -> id = $('#status_id').attr('data-id') $.get "/orders/#{id}", (data) -> console.log("#{data.status}") if data.status is 'expired' order.stop_polling() $ -> order.start_poll() 回答1: setInterval returns a new timer ID every time you call it