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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:16:39+00:00 2026-05-30T08:16:39+00:00

can someone please explain to me the following JavaScript design pattern example and what

  • 0

can someone please explain to me the following JavaScript design pattern example and what it’s trying to accomplish?

    var Knockback = { };
    Knockback.Observables = (function () {

        function Observables(model, mappings_info, view_model) {
            this.model = model;
            this.mappings_info = mappings_info;
            this.view_model = view_model;


            //logic in here
        }
        Observables.prototype.destroy = function () {
            //logic in here


            this.view_model = null;
            this.mappings_info = null;
            return this.model = null;
        };

        return Observables;
    })();

Knockback.observables = function(model, mappings_info, view_model, options) {
    return new Knockback.Observables(model, mappings_info, view_model, options);
};
  • 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-30T08:16:41+00:00Added an answer on May 30, 2026 at 8:16 am

    Knockback is a namespace. Values are stored inside Knockback so they do not clash with any global variables.

    Observables is a constructor sitting inside Knockback. All of the logic is inside a closure ((function () {})()) for modularity

    observales is used as a method of returning an instance of Observables, This is a way that people can use whats known as “scope safe constructors”. In javascript if you call a constructor without new, then the this object defaults to the window, polluting your global namespace again.

    I’m not sure how much you know about javascript, but I hope this helps.

    ——————————– updated ————–

    1) The closure functions the same as without a closure, that is correct (At the time of my answer i didnt know that there were no “private” variables). But this pattern also allows you to place this constructor wherever you please. Imagine if the namespace (Knockback) name changed to KB. You could place the constructor there without even needed to change a line of code inside the closure.

    2) The Knockback.observer function may be a bloat (which i personally dont think it is) but the “scope safe” factor is considered a best practise. consider:

    var standardCorrectInvokation = new Knockback.Observer('model', 'mappings_info', 'view_model');
    
    var aboutToLooseMyJobInvokation = Knockback.Observer('this', 'is', 'un-intuative');
    //goodbye global namespace
    alert(window.model); // this
    alert(window.mappings_info); // is
    alert(window.view_model); // un-intuative
    //goodbye job at reputable web firm
    

    Id like to point out that the boys as ES5 camp fixed this problem, but strict mode is not implemented in all browsers yet (IE.. ahem ahem)

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

Sidebar

Related Questions

Can someone please explain what the following javascript statement is doing? var default_hide =
Can someone please explain what the following function does. I am learning Asp.net MVC
I am learning javascript and can someone please explain the following code snippet for
Can someone please explain the following. I've scoured the net for ages trying to
Can someone please explain why is meta class used in the following example. Ex:
Can someone please explain why the following doesn't work works: function displayResults(data) { $(#odNextPage).click(function()
Can someone please explain the following How was the first JDK release unit Tested?
Can someone please explain what the & does in the following: class TEST {
Can someone please explain how you can write a url pattern and view that
Can someone please explain me the following code snippet? value struct ValueStruct { int

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.