Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:28:08+00:00 2026-05-28T05:28:08+00:00

Despite I have been using MVC in PHP many times, I found out that

  • 0

Despite I have been using MVC in PHP many times, I found out that it is quite different in Javascript. I’m reading MVC in Javascript over the web, but many of them have a different implementation. I came up with a simple MVC, but I think this is not correct. Is this acceptable or completely wrong?

var AppView = View.extend({

    init: function()
    {

        // listen to Model changes
        this.listen("counterChanged", $.proxy( this.updateCounter, this ));

        // assign click event; call controller method
        this.container.find("#increase").click( this.callback( this.Controller, "increase" ));
        this.container.find("#decrease").click( this.callback( this.Controller, "decrease" ));
    },


    updateCounter: function( evtData )
    {
        this.container.find("#counter").html( evtData.newValue );
    }

});

var AppController = Controller.extend({

    increase: function()
    {
        this.Model.update("counter", this.Model.get('counter') + 1 );

    },

    decrease: function()
    {
        this.Model.update("counter", this.Model.get('counter') - 1 );

    }

});


var AppModel = Model.extend({


    onUpdate_counter: function( newValue )
    {
        this.fireEvent("counterChanged",{
            newValue: newValue
        })
    }

});




var App = {}

$(document).ready(function(){

    App.Model = new AppModel({
        counter: 0
    });
    App.Controller = new AppController( App.Model );
    App.View = new AppView("#app", App.Controller );    

    App.Model.setView( App.View );

});

HTML:

<div id='app'>

    <div id='counter'>0</div>

    <a id='increase'>Increae</a>
    <a id='decrease'>Decrease</a>

</div>

View listens to changes in the model and assigns events to html anchors. View calls the controller when the anchors are clicked then controller updates the model.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:28:08+00:00Added an answer on May 28, 2026 at 5:28 am

    This is classic 1979-type MVC:

    • controller updates models
    • models update views via listeners

    PHP/Rails (web request/response in general) is a slightly different type of MVC (constricted by the request/response nature of the web):

    • controllers update models
    • controllers take data from models and send it to views

    In both types, view events trigger controller actions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code here that does not work despite me using
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been developing web apps (primarily) using php and a bit of python,
There have been many threads started over the confusion in the way that Math.Round
I have a problem with a data-bound DataGrid control, in that despite each column
We have a page that ordinarily has two elements arranged side-by-side. Despite exploring a
I have been trying to figure out how to do this and it seems
EDIT: I have been using Postgres with PostGIS for a few months now, and
In Vista, I have been using an IFileSaveDialog to let users pick a save-as
Despite reading many articles (some on this board) I am still scratching my head

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.