Я пытаюсь обновить свой typeahead с помощью функции debounce, и до сих пор я имел успех только со следующим кодом. Он выполняет запрос debounce, но когда я определяю функцию как something = func (args) ->
, он не привязан к экземпляру View, и я не могу получить доступ к коллекции View через @collection
. Однако любой другой метод, определенный как something: ->
, можно найти в экземпляре View. Почему это происходит? Благодарю.Я теряю контекст `this` в представлении Backbone
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