views:

179

answers:

3

Hi,

what is the best way to create MVC architecture in jQuery?

Should I use jQuery.extend()?

jQuery.extend({
  View: function(){}
});

...or jQuery Plugin?

(function($) {

  $.fn.model = function() { return this; }; 

})(jQuery);

...or just objects in JavaScript?

var model = {}
var view = {}
var controller = {}

Thank you!

+2  A: 

Here is a great approach using jQuery.extend: http://welcome.totheinter.net/tutorials/model-view-controller-in-jquery/

Simeon
+3  A: 

Just use objects in javascript. The view can contain all the knowledge of things like jquery and other UI concerns, while the controller/model can deal with other logic and communication with the server (assuming ajax). I wrote a blog post about this:

MVC Pattern with Javascript

Joel Martinez
A: 

MVC in javascript? are you using JSP? I just dont get how that would benefit you one bit.

Take advantage of the native coding practices in Jquery.

IE. code in jQuery's way.. chaining functions and extending it, by creating plugins that can also be chained. That's one of jQuery's strongest arguments for using it, over other frameworks.