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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:01:28+00:00 2026-06-07T15:01:28+00:00

This example is borrowed from Backbone directory demo app https://github.com/ccoenraets/backbone-directory/blob/master/web/js/utils.js#L11 // The Template Loader.

  • 0

This example is borrowed from Backbone directory demo app
https://github.com/ccoenraets/backbone-directory/blob/master/web/js/utils.js#L11

// The Template Loader. Used to asynchronously load templates located in separate .html files
window.templateLoader = {

    load: function(views, callback) {

        var deferreds = [];

        $.each(views, function(index, view) {
            if (window[view]) {
                deferreds.push($.get('tpl/' + view + '.html', function(data) {
                    window[view].prototype.template = _.template(data);
                }, 'html'));
            } else {
                alert(view + " not found");
            }
        });

        $.when.apply(null, deferreds).done(callback);
    }  
};

You initialize this with array of strings [views] and [callback] function.

My question is how window[view] (click above link to exact position in the code) can be checked if (as far as I see) wasn’t be initialized previously? If I’m not precise please write this in comments.

  • 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-07T15:01:30+00:00Added an answer on June 7, 2026 at 3:01 pm

    If I’ve understood your question correctly, then when you call templateLoader.load you pass in 2 arguments; views and callback. We can assume that views is an array, since we then iterate over that array with the jQuery .each() method. The callback to .each() is passed the element of the views array that corresponds to the current iteration. That argument is named view.

    So view is some arbitrary value that was stored in the views array. We then try to find a property of window with the identifier that matches the value of view. If view === "james" we are looking for window.james.

    If you look at some of the views in that app you will see that they are defined like this:

    window.ContactView = Backbone.View.extend({
        // Some methods
    });
    

    So ContactView is a property of window, and we could call templateLoader.load like the following to load that template:

    templateLoader.load(["ContactView"], someCallbackFn);
    

    And you can see where that actually gets called in main.js.

    So what’s actually happening is a bunch of properties of window are defined in various other files, and then loaded by the template loader, by passing an array of identifiers to it.

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

Sidebar

Related Questions

The following gist: https://gist.github.com/1876791 (borrowed from the demo in this question ) is a
using this example on dynamic list https://github.com/sandeepleo11/Dynamic-Select-Menus-in-Rails-3 I managed to get dynamic select in
This example is from the PLINQ MSDN article: http://msdn.microsoft.com/en-us/library/dd997399.aspx var queryA = from num
This following code example is borrowed from MSDN here . I am not getting
I have an Ember.js app as follows (borrowed from this article on andyMatthews.net): View:
This example is taken from the Linux System Programming book, page 88. Code: http://pastebin.com/mEfmHbPP
Re this example from the Android developer blog http://android-developers.blogspot.com/2011/04/customizing-action-bar.html It says that to style
This example is simplified a bit, but in my ASP.NET web page in my
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT
in this example http://sorgalla.com/projects/jcarousel/examples/static_controls.html i need an active state on li so it should

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.