I am currently working on enhancing my typeahead feature with debounce functionality. So far, I have achieved some success with the following code. The code successfully debounces the request. However, I encountered an issue where when I define a function as something = func (args) ->
, it does not get attached to the View instance. As a result, I am unable to access the View's collection through @collection
. Strangely, every other method defined as something: ->
can be easily found on the View instance. Can someone explain why this happens? Thank you.
class productsView extends Marionette.CompositeView
onDomRefresh: (options) ->
@initTypeahead()
initTypeahead: ->
console.log @
# outputs: productsView{...}
@ui.typeahead_input.typeahead {
hint: true
highlight: true
minLength: 1
},
source: (q, sync, async) =>
requestDebouncer q, sync, async
requestDebouncer = _.debounce (q, sync, async) =>
console.log @
# outputs: function productsView()...
console.log "debounced"
, 300