bloody-jquery-plugins icon indicating copy to clipboard operation
bloody-jquery-plugins copied to clipboard

Pubsub scope issues with "this"?

Open jonsykes opened this issue 13 years ago • 1 comments

regarding pubsub https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js

I was recently trying to use this within a class, by subscribing and then the callback was "this.handlerMethod" but when I fired the pub, the method was being fired, but if I console.log'ed the this value within the method it was now the topic class.

Not sure if that makes sense.

jonsykes avatar Jan 25 '12 14:01 jonsykes

Just to explain my thought process a little more.

Doesn't this line


this.apply(d, args || []);

mean that the callback function we've stored is now called in the scope of "this", where "this" is the scope of the topic.publish object?

jonsykes avatar Jan 25 '12 20:01 jonsykes