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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:21:49+00:00 2026-06-12T16:21:49+00:00

(Edited to greatly simplify) On node I have the following server.js file. var Backbone

  • 0

(Edited to greatly simplify)

On node I have the following server.js file.

var Backbone = require('backbone');

var Tweet = Backbone.Model.extend({});
var Tweets = Backbone.Collection.extend({
    model : Tweet,
    url: function () {
        return 'http://search.twitter.com/search.json?q=backbone'
}
});

var myTweets = new Tweets();
myTweets.fetch();

When I run this, I get an error that says. “Cannot call method ‘ajax’ of undefined” (1359:14)

basically that is the result of $ being undefined. Why is it undefined? Well there are a number of intermediate steps but when the file is loaded, it is expecting “this” to be “window” in browser or “global” on server. executed on node “this” = {}.

So the question, “How do I set ‘this’ to global” inside the backbone.js file?

  • 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-12T16:21:50+00:00Added an answer on June 12, 2026 at 4:21 pm

    On Backbone >= 1.x, you can simply assign Backbone.$ rather than using Backbone.setDomLibrary.

    Solution for Backbone < 0.9.9

    The first issue you need to address is how you are running this on Node anyway. Nodejs is a server-side JS environment, but it does not include any logic for controlling a DOM. For that you need to load something like JSDom.

    When you have some DOM environment set up, you can load jQuery and your code into it and it should work just like a browser.

    To answer your question specifically though, loading jQuery into the global is a bit of an ugly way to do it. You should use Backbone’s setDomLibrary function to set $ to what you want.

    Try something like this:

    if (typeof exports !== 'undefined') {
        MyModels = exports;
        Backbone.setDomLibrary(require('jquery'));
        server = true;
    } else {
        MyModels = this.MyModels = {};
    }
    

    This will fail if you try to do any DOM functions though.

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

Sidebar

Related Questions

First off I'm running Ubuntu 9.10 I've edited the /etc/environment file to look like
I have a text file: DATE 20090105 1 2.25 1.5 3 3.6 0.099 4
Good morning! I use Backbone.js 0.9.2 (and CakePHP). My model has 4 fields: id
I went off an tutorial when creating this form, and have edited and formatted
I am trying to understand virtual memory paging. I have the following code snippet
EDITED*** Thank you for the help below. I understand $(this).children() now and I have
I have recently edited a fellow student's data collection software to my specifications. The
Edited at the request of commenters. I hope this is compliant. First post! Trying
Edited: I want to get the actual with of the document with JS. I
(Edited for clarification) My (non-OSGi) application build is in Gradle, and I am trying

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.