Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To be honest, MVC isn't well-suited for Javascript. It can support the basic fundamentals of the design, sure - you can create pseudoclasses to act as controllers or models, support basic inheritance, and you can have it manipulate or create any number of DOM elements, but there's a price that you pay for that - in overhead, accessibility, and usability.</p> <p>In my opinion, I consider Javascript more of an augmentation - the KISS mentality exists for a good reason. If you're interested in better ways to organize your code, there's always the option of packaging related functionality into modules (sic) and abstracting out portions as appropriate. For example, creating a factory to do more complex AJAX request management, or a pseudoclass to handle processing of similar types of data. Using a standard base function for controllers, another for models, etc, as prototypes for new instances of those objects can accomplish similar functionality... but again, it's sort of going against the grain of Javascript.</p> <p>However, if you're stuck on the MVC idea just for the sake of structure, consider something like the following:</p> <pre><code>;(function(window, $) { /** * Event Object * A quick description goes here. **/ var Events = window.Events = { 'bindTrackables': function() { $('a.trackable').live('click', function() { if(!_gaq) _gaq = []; _gaq.push(['_trackPageview', '/ajax/foobar']); }); }, 'bindSomeEvent': function() { // etc } }; /** * Data Cache * I'll need to remember stuff later, so I store it here **/ var Cache = window.Cache = { 'data': {}, 'store': function(key, value) { Cache.data[key] = value; }, 'fetch': function(key) { return Cache.data[key]; } }; /** * Request Object * Stores native AJAX requests for later use **/ var Request = window.Request = { 'current_requests': [], 'send': function(url, type, data, callback) { Request.current_requests.push($.ajax({ 'url': url, 'type': type, 'data': data, 'callback': callback })); }, } // add some private logic here })(window, jQuery); </code></pre> <p>It's extremely basic, but you get the idea. Modular code is key... in JS, this is more important than forcing your application (or the language) to fit a certain style.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload