Home > brief news, GeeCON, Google > jQuery 1.4 Released: to 14 days of jQuery

jQuery 1.4 Released: to 14 days of jQuery

Well jQuery 1.4 has been released and brings to you couple of important and very useful changes … Although there were many speculation about jQuery maintenance new Release 1.4 became to be surprised … Now just I go through couple of them in GeeCON intent …

1.  Control a Function context …

Query 1.4 release provides the  proxy” function under the jQuery name space. This function takes two arguments  (a “scope” and a method name or a function and the defined “scope“).  JavaScript  “this” keyword can be quite tricky to keep a hold of.

As we have an example of  “conSPACE” object which contains two properties, “clickHandler” method and a config object:

var conSPACE = {
 config: {
  clickMessage: 'GeeCON Planet is here!'
 },
  clickHandler: function() {
  alert(this.config.clickMessage);
 }
};

The “clickHandler” method, when called like “conSPACE.clickHandler()” will have “conSPACE” as its context, meaning that the “this” keyword will allow it access to “conSPACE“.  Actually this works very simply:

app.clickHandler(); // " GeeCON Planet is here!!" is displayed

Do try to  bind it as an event handler:

jQuery('a').bind('click', conSPACE.clickHandler);

When we click an anchor it doesn’t appear to work (nothing is alerted). That’s because jQuery (and most sane event models) will, by default, set the context of the handler as the target element, which is that the element that’s  been clicked will be accessible via “this“. But we don’t want that, we want “this” to be set to “conSPACE“. Achieving such intent is  in jQuery 1.4 simple:

jQuery('a').bind(
   'click',
    jQuery.proxy(conSPACE, 'clickHandler')
);

This is it, whenever an archor is clicked, just GeeCON Planet is here! gonna be displayed … for more read about jQuery.proxy() here

2. Binding Multiple Event Handlers together …

This feature is really cool because instead of chaining couple of methods together, you can do just as one call and bind them by using .bing()

jQuery('#GeeCON).bind({
   click: function() {
   // do something
 },
   mouseover: function() {
   // do something
 },
   mouseout: function() {
   // do something
 }
})

3. Passing Attributes to jQuery1.4 …

Before rel. 1.4  jQuery supported adding attributes to an element collection via the useful “attr” method, which can be passed both an attribute name and value, or an object specifying several attributes. jQuery 1.4 adds support for passing an attributes object as the second argument to the jQuery function itself, upon element creation.

jQuery('<a/>', {
 id: 'GeeCON',
 href: 'http://www.geecon.org',
 title: 'Become a GeeCON attendant',
 rel: 'external',
 text: 'Join GeeCON !'
});
 

attribute “text” is utilized by jQuery 1.4 where jQuery causes to call “.text()” method, passing “Join GeeCON” as its only an argument of.  Other similar example  where “id” is added as regular attribute:

jQuery('<div/>', {
  id: 'GeeCON',
  css: {
    fontWeight: 222,
    color: 'Yellow'
  },
  click: function(){
    alert('GeeCON has been reached!');
  }
});

There are lot of other new features (17) which all are interesting in making jQuery 1.4 usage more easier … Have a look here for more Version 1.4 . Do not forget about GeeCON conference ..

Advertisements
Categories: brief news, GeeCON, Google
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: