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 8257103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:05:15+00:00 2026-06-08T02:05:15+00:00

I want to implement MVC pattern in JavaScript, but I have a problem with

  • 0

I want to implement MVC pattern in JavaScript, but I have a problem with Controller implementation.

MVC concepts are clear to me. I understand how MVC works. I don’t think that events is appropriate way build a Controller. And there are a lot of dependences because of edition of the event in JavaScript.
I would like to see some small example of implementation of MVC Controller in JavaScript.

p.s. I want to implement MVC pattern by using only JavaScript, but I don’t want to use any MVC open-source frameworks.

p.s. I don’t want you to do my homework, but I really don’t understand how to imprelent Controller in JavaScript.

  • 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-06-08T02:05:17+00:00Added an answer on June 8, 2026 at 2:05 am

    basicly MVC is based apon the Observer pattern (and controller is also)

    How you can implement Observer inside of Javascript?

    function Observer() {
        var subscribers = [];
        return {
            subscribe: function(eventName, object) {
                subscribers.push({ event: eventName, target: object });
            },
            unsubscribe: function(object) {
                var indexToDelete = subscribers.indexOf(object);
                subscribers.splice(indexToDelete, 1);
            },
            trigger: function(eventName, p1, p2, p3, p4, p5) {
                for (var i = 0; i < subscribers.lenght; i++) {
                    if (subscribers[i].event == eventName) {
                        //target object must implement this function
                        subscribers[i].target[eventName](p1, p2, p3, p4, p5);
                    }
                }
            }
        }
    }
    

    And how you can use it?

    var model = { 
        fireChangesInsideOfModel: function(p1){ 
            //do some model update logic here
        } 
    }
    var controller = Observer();
        controller.subscribe("fireChangesInsideOfModel", model);
    
    controller.trigger("fireChangesInsideOfModel", 11231); // 11231 - is an example of a parameter
    

    Hope this helps you..

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

Sidebar

Related Questions

I have a problem and I want to implement the MVC pattern to my
I have implemented a repository pattern in my asp.net mvc web application... But i
I have read a lot about MVC design pattern, but some of the things
I have implemented my mvc base controller called DefaultController using dependency injection pattern in
I want to implement MVC in my Android application for reasons I have heard
I want to implement MVC arch. in silverlight application. I have the following questions:
I started my project in Asp.net MVC(c#) & SQL Server 2005.I want to implement
I want implement in my software solution an VBA editor but in c# 3.0.
i starter in jqgrid, i want implement inline edit in jqgrid i have this
The well known Command pattern is used often when you want to implement a

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.