documentcloud/underscore — pull request #952 by ainth (2013-01-25 16:33:06+00:00)
Title: Calling a _.debounced function should return the timeout

Currently there is no way to clear a debounced function that has been called. This
is problematic for something like a Backbone view where we need to stop everything
as soon as remove is called. Here is what the changes will let us do:

class MyApp.MyView extends Backbone.View

initialize: ->
@doStuffSoon = _(@doStuff).debounce(2000)

someEvent: ->
@doStuffTimeout = @doStuffSoon()

remove: ->
clearTimeout(@doStuffTimeout)

doStuff: ->
# This should never be called after the view has been removed
alert('stuff!')