Marc
Marc

Reputation: 14401

Custom Class Events in jQuery?

Is there a standard way in jQuery to publish and subscribe to custom class events? There are countless examples of "custom events" which are always related to some HTML element. But what if the javascript class Person() want's to publish and fire an event iAmSick which is listened for by a class HealthProfessional()? I guess it could be done with callbacks but isn't there something like asEvented?

Upvotes: 3

Views: 654

Answers (2)

Joseph Silber
Joseph Silber

Reputation: 220146

jQuery is a cross-browser JavaScript library that provides abstractions for DOM traversal, event handling, animation, and Ajax interactions for rapid web development.

So the short answer is: no. Thre is no "standard way in jQuery to publish and subscribe to custom class events".

However, if you want to create your own solution, but don't want to start from scratch, I'd highly recommend that you read Darcy Clarke's article:

Library Agnostic Pub/Sub (Publish / Subscribe).

Upvotes: 2

Pointy
Pointy

Reputation: 414086

jQuery is a DOM-oriented library, to the extent that the maintainers generally resist attempts to introduce general-purpose programming tools such as the pub/sub system you describe.

Upvotes: 0

Related Questions