user710502
user710502

Reputation: 11471

Prototype "classes" vs Jquery

I currently work with prototype, so for instance if i want to create a class or something i would do something like (using it with asp.net)

function MyTestClass()
{

this.MyHtmlDiv = $("myHtmlDiv");
this.MyButton = $("myButton");
this.init();
}

MyTestClass.prototype.init = function()
{
  Event.Observe(...some code here ..);
  Event.Observe(...more code...);
}

So you get the idea. I like the way it is organized but I have read here in other posts that jquery is better. I would like to start using it but.. is it possible to create "classes" like this, neat?. I usually have a separate .js file for each aspx page. How can I create a class like this with JQuery?

Any pointers, links, ideas or suggestions would be appreciated. When I google this, I see some jquery functions but havent really found a nice template that i can follow to maintain it like above if i was to move to jquery.

Upvotes: 3

Views: 160

Answers (1)

xdazz
xdazz

Reputation: 160853

jQuery has no confliction with the style you use now, you just need to change your mind of how jQuery selector work and how to bind event handler etc.

function MyTestClass() {
  // note jQuery's selector is different from Prototype    
  this.MyHtmlDiv = $("#myHtmlDiv");
  this.MyButton = $("#myButton");
  this.init();
}

MyTestClass.prototype.init = function() {
  this.MyHtmlDiv.on('event_type', function() {
    // some code
  });
  this.MyButton.on('event_type', function() {
    // some code
  });
}

Upvotes: 2

Related Questions