Is there a jQuery Equivalent of YUI 2 Custom Event Publish/Subscribe Event Model?

I learned how to develop in Javascript using the YUI 2 library and was wondering if there were a jQuery equivalent of Custom Events ([http://developer.yahoo.com/yui/event/#customevent][1]) Specifically, I want to be able to define custom events without having to attach the listeners initially. In YUI, I would create a page class and declare different custom events that can be subscribed to. Below is some example code to demonstrate what I want to do, but with jQuery function ListPage() { var me = this; this.initEvent = new YAHOO.util.CustomEvent("initEvent"); this.init = function() { // initialize events, DOM, etc this.initEvent.fire(me); } } In application Javascript, I would then like to subscribe to the initEvent. var page = new ListPage(); page.initEvent.subscribe( function (type, args) { // do stuff here } ); page.init(); Are there any tutorials/examples of something like this in jQuery? I understand I can do something similar using bind() and trigger(), but the impression I get is I have to pass in an event handler when I call bind(). Is it possible in jQuery to create the custom event, but pass in the event handler later? I hope my question makes sense. thanks! [1]: http://developer.yahoo.com/yui/event/#customevent

以上就是Is there a jQuery Equivalent of YUI 2 Custom Event Publish/Subscribe Event Model?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏