views:

1038

answers:

2

Can anybody send me the good links of the observer pattern in JavaScript?

+1  A: 

Remember that JavaScript is object-oriented, but doesn't have native classes. There are many class systems that people have written to extend JavaScript to a more familiar classical inheritance model. Whether you choose to follow that route is up to you. javaScript is certainly malleable enough to make it fit many ways of programming.

Do you have specific problem you're trying to solve? If so, there may be a natural JavaScript solution. If you're already using a library that adds some kind of class system (Prototype, MooTools, Dojo, and some others do, but jQuery doesn't), you might be looking for an example using that library.

If you're using js.class, try this link.

Here's a comparison of a Java solution to a JavaScript solution.

Nosredna
A: 

From a library standpoint, check out custom events in YUI and jQuery.

  • In jQuery, bind() to a custom event.
  • In YUI, scroll down on the page until you find the section Subscribing (Listening) to a Custom Event

Also, the book Pro Javascript Design Patterns has an example. You won't find the full text anywhere, but here's the Google Books link

John