2

I am trying to understand if MVC (as it works in Java desktop applications, for example) is applicable to JavaScript web applications.

By MVC I mean the following :

  • Model is data that represent the application state. It is not aware of the page DOM.
  • View is the DOM tree and functions, which listen to the Model changes and update the DOM
  • Controller listens to user gestures (e.g. "button pressed"), calls the server, and updates the Model rather than View.

I looked through few JavaScript applications and saw something different. They do not have clear distinction between Model and View. That is, the application state is scattered over the DOM tree and Controller (e.g. ajax callbacks) updates the View (DOM tree) directly.

Now I wonder if the MVC as described above is really applicable to JavaScript applications running in the browser. What do you think?

4
  • 1
    it's "JavaScript", with a single word :) Commented May 14, 2012 at 10:31
  • MVC is a pattern and can be applied anywhere there's a way to separate the concerns, including on the client side. A trivial search for "javascript mvc" probably would have answered this question far more completely. Commented May 14, 2012 at 11:16
  • @DaveNewton Thanks. Do you have any experience with MVC in JavaScript ? For what kind of applications would you recommend it ? Commented May 14, 2012 at 13:54
  • Any kind, although for small apps, or pages with very light client-side requirements, it's probably not worth it unless the team is already using a framework. The more the client side needs to do, the more value molding the app into a framework brings. Like anything else, "it depends". Commented May 14, 2012 at 14:04

3 Answers 3

2

MVC with JavaScript exists and is already possible. There are tons of library out there. I give you some ressource to dig in:

Addy Osmani blog contains a lot of informations about JavaScript design patterns, and especifically about MVC, you should have a look there http://addyosmani.com/blog/. He also has written a book about design patterns in Javascript http://addyosmani.com/resources/essentialjsdesignpatterns/book/

Sign up to request clarification or add additional context in comments.

Comments

1

You can use MVC for JavaScript applications, and there is no shortage of frameworks to help.

There are plenty of applications that don't though (in part because JavaScript hasn't been widely considered a "serious" language until recently, so such development practises are new to large parts of the JS community).

Comments

1

In JavaScript, due to it's dynamic nature, these patterns vary, depending on the programmer that builds them and the applications that are built on it. And MVC is just one in a whole bunch of patterns.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.