Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The $on()’s callback is bound to the event object #130

Closed
bpierre opened this issue Feb 23, 2014 · 2 comments
Closed

The $on()’s callback is bound to the event object #130

bpierre opened this issue Feb 23, 2014 · 2 comments

Comments

@bpierre
Copy link

bpierre commented Feb 23, 2014

var vm = new Vue({
    created: function() {
        console.log(this === vm) // true

        this.$watch('foo', function() {
            console.log(this === vm) // true
        })

        this.$on('bar', function(value) {
            console.log(this === vm) // false
        })
    }
})

Shouldn’t this be the current VM here? Maybe the event could be passed as a second parameter.

@marfalkov
Copy link

Since I'm using this way it doesn't really bother me but this is a good point.

var vm = new Vue({
    created: function() {
        var self = this
        console.log(self === vm) // true

        this.$watch('foo', function() {
            console.log(self === vm) // true
        })

        this.$on('bar', function(value) {
            console.log(self === vm) // true
        })
    }
})

@bpierre
Copy link
Author

bpierre commented Feb 23, 2014

Yes that’s what I am doing at the moment, I am just wondering if it’s on purpose.

yyx990803 added a commit that referenced this issue Feb 23, 2014
This has a few benefits
- no longer need to shiv the difference between Component's emitter
  & Browserify's emitter (node version)
- no longer need to hack around Browserify's static require parsing
- able to drop methods not used in Vue
- able to add custom callback context control, as mentioned in #130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants