pattern, development

small Javascript Objects example

In addition to article "Javascript object notation" I still have a small example lieing around.

Its just a simple table element that is bind to a javascript object that is responsible for controlling the actions related to this table widget - the widgets with its javascript controller part are independend from each other. In theory they could delegate the actions in that widget to a coresponding controller on the server.

To the example

There is one "trick" to mention. We need a way to bind the html element "table" to the object that should control this widget. With jQuery you can do this with the ".data" method - it allows you to bind any stuff to a html element.

So in this case - to ensure that on a click on the "change color" link the correct object answers - we just bind the object itself to the link element:

// register for clicks on the "change color Link"
this.registerEvents=function() {
$('#'' .click').data('object',this).click(function(event) { $(this).data('object').clickColorAction(); });

blog comments powered by Disqus
  1. Christian 21.10.09 18:44

    The article are great. Thanks. Thumbs up!

  2. runescape gold 02.06.09 08:31

    Your article very interesting, I have introduced a lot of friends look at this article, the content of the articles there will be a lot of attractive people to appreciate, I have to thank you such an article.