开发者

How can I implement the Observer pattern in a Firefox Extension?

I'm trying to implement a simple Observer pattern within a Firefox extension. This initially appears relatively easy, but I thought it made sense to get the functionality from a library

  • JS.Observable seemed like a good option, but I found that JS开发者_JS百科.Class is unhappy running from within an extension as the DOM is not where it expects it to be, etc.

  • JQuery's bind appears to offer an alternative and apparently JQuery should work inside the extension's context. This relies on binding to a DOM object which seems a little nasty for what I'm trying to do.

  • YUI's Custom Event seems ideal, but YUI does not work inside extensions.

Is there a good implementation of the Observer pattern that I can use, or should I just write it by hand following something like this from O'Reilly Answers?


If you're working completely in chrome code, I would just use the Observer Service.


The Publish/Subscribe with jQuery Custom Events blog post explained that JQuery's bind could be applied to any object, not just a DOM object. So, that's the solution I've gone with, I followed A Guide To Using jQuery Inside Firefox Extension to get JQuery working nicely inside my namespaced extension.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜