jQuery plugin and prototype class

Posted by Shanison on Stack Overflow See other posts from Stack Overflow or by Shanison
Published on 2010-06-14T09:55:46Z Indexed on 2010/06/14 10:02 UTC
Read the original article Hit count: 155

Filed under:
|

Hi I am converting some prototype javascript to jQuery javascript.

In prototype we can do Class.create to create a class. However, jQuery doesn't provide this. So I was thinking to rewrite the class into a jQuery plugin. Is this the best practice? My concern is that if I do all for the class, then I will add a lot of things to jQuery object.

The other alternative is to use some extra lines of codes I found http://ejohn.org/blog/simple-javascript-inheritance/#postcomment. Then you can do the following:

var Person = Class.extend({
  init: function(isDancing){
    this.dancing = isDancing;
  },
  dance: function(){
    return this.dancing;
  }
});

Which one is better, please advise. Thank you very much!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about prototype