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

  • Home
  • SEARCH
  • 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 8421199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:05:02+00:00 2026-06-10T03:05:02+00:00

Hi could somebody give me an understandable example of a requirejs singleton with underscore’s

  • 0

Hi could somebody give me an understandable example of a requirejs singleton with underscore’s once()?

I have this as far:

define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {

    var SingletonModel = Backbone.Model.extend({
        urlRoot: "/model",
        idAttribute: "_id"
    });

    return function() {
        once(SingeletonModel);
    };

});

As you see especially the return statement is totally crap. I just have no idea how to singletony a Backbone.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-06-10T03:05:04+00:00Added an answer on June 10, 2026 at 3:05 am

    I’m doing this

    define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
    
        var SingletonModel = Backbone.Model.extend({
            urlRoot: "/model",
            idAttribute: "_id"
        });
    
        if (SingletonModel.prototype._instance){
            return SingletonModel.prototype._instance;
        }
        SingletonModel.prototype._instance = new SingletonModel;
        return SingletonModel.prototype._instance;
    
    });
    

    then you just require this file and use it as it would be an instance.

    EDIT:
    Haven’t tried it, but the usage of once() should be in your case

    underscore.once()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could somebody give me the working example of nested form using mongoid? My models:
Could somebody please give their input into the following scenario: I have an Administrator
Could somebody give me a pointer on why I need to add my project
could somebody please take a look at this http://jsfiddle.net/bloodygeese/EzkFR/1/ My aim is to on
Could somebody please explain what this notation is in javascript? What is function(d) doing?
Could somebody please help me get Clang up and running? (I don't have 3.2)
What's the difference between FirstOrDefault() and FirstOrDefault<string>() in LINQ ? Could somebody give me
Could somebody please give me a few pointers on how to add a sliding
I'm brand new to Git. Could somebody give me a rundown of the typical
Could somebody give me a brief overview of the differences between HTTP 1.0 and

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.