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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:51:53+00:00 2026-06-12T05:51:53+00:00

In the first few lines of backbone.js, I don’t see why they are testing

  • 0

In the first few lines of backbone.js, I don’t see why they are testing for undefined on exports or require

It seems obvious that it would be undefined as they did not set it. If it was a global(window) object then they would have said it explicitly.

root.exports  // they don't do this
root.require

Why do they check this?

typeof exports !== 'undefined'

and this

if (!_ && (typeof require !== 'undefined'))

and this from above

!_

Full Snippet

(function(){
    var root = this, 
        previousBackbone = root.Backbone,
        slice = Array.prototype.slice,      
        splice = Array.prototype.splice,
        _ = root._,
        Backbone;
    if (typeof exports !== 'undefined') {
        Backbone = exports;
    } else {
        Backbone = root.Backbone = {};
    }
    Backbone.VERSION = '0.9.2';
    if (!_ && (typeof require !== 'undefined')) {
        _ = require('underscore');
    }
  • 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-12T05:51:54+00:00Added an answer on June 12, 2026 at 5:51 am

    That’s there to allow Backbone.js to be used as a Common.js module I believe. More details here: http://wiki.commonjs.org/wiki/Modules/1.1

    Specifically this bit:

    In a module, there is a free variable called “exports”, that is an object that the module may add its API to as it executes.

    Also, this bit covers your question about require:

    In a module, there is a free variable “require”, that is a Function. The “require” function accepts a module identifier. “require” returns the exported API of the foreign module.

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

Sidebar

Related Questions

We often see websites that display first few lines of an article and then
Here are the first few lines of an R function that works: teetor <-
I have a large data frame that Im working with, the first few lines
I have a large data frame that Im working with, the first few lines
I have the first few lines of a text file fx.txt with the following
I have a text file with few first few lines not required and then
I want to log only the first few lines of Exceptions in my program.
My logcat window in Eclipse only displays the first few lines of the StackTrace
I am reading in a flat text file, normally the first few lines are
How to get the first few lines from a gziped file ? I tried

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.