davej / angular-classy

Cleaner class-based controllers with Angular 1
http://davej.github.io/angular-classy/
813 stars 27 forks source link

watch 'this' is window #18

Closed amcdnl closed 10 years ago

amcdnl commented 10 years ago

When I do a watch, I often need to debounce the call, instead of having to define a function it would be nice to use this utility directly.

Problem is the this reference is window in this case:

watch: {
        '{object}report': this.debounce(this.SearchModel.findAll, 500, true)
    }

The debounce is a factory utility, code here: https://gist.github.com/amcdnl/9238250

davej commented 10 years ago

Javascript will execute the function immediately with this syntax (it won't wait for the watch). This is probably not what you want to do. You will need to wrap it in a function, there is no way around this.

amcdnl commented 10 years ago

An interesting approach might be to allow string interpolation with 'mixins' like:

 '{object}report:debounce(500)': this.SearchModel.findAll

execute everything : and pass args in () to the fn