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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:27:30+00:00 2026-05-31T20:27:30+00:00

I just started out with RequireJS, but i’m stuck at the part where i

  • 0

I just started out with RequireJS, but i’m stuck at the part where i want to use one js file which has two defines() in it, like this:

Filename: test.js

define('test1', ['jquery'], function() {
    return {
        method1 : function () {
            console.log("test1 - method 1");
        },

        method2 : function () {
            console.log("test1 - method 2");
        }
    }
});

define('test2', ['jquery'], function() {
    return {
        method1 : function () {
            console.log("test2 - method 1");
        },

        method2 : function () {
            console.log("test2 - method 2");
        }
    }
});

I also have a bootstrap,js file which is automatically loaded by the RequireJS framework:

require(['jquery', 'test', 'test2'], function ( $, t1, t2 ) {
    console.log(t1);
});

It does find the 2nd param, the ‘test’ file. Only, it returns a ‘null‘. It can’t find ‘test2’ because it tries to look for a file called ‘test2.js’. Actually i’d like to do something like:

require(['jquery', 'test.test1', 'test.test2'], function ( $, t1, t2 ) {
    console.log(t1);
});

But in anyway, i’d like to get a handler to both the objects. What am i doing wrong??

  • 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-31T20:27:32+00:00Added an answer on May 31, 2026 at 8:27 pm

    You cannot export two different modules like this. If you want to keep them as “submodules” of ‘test’, the right way would be to do:

    define('test', ['jquery'], function() {
        var exports = {};
        exports.test1 = {
            method1 : function () {
                console.log("test1 - method 1");
            },
    
            method2 : function () {
                console.log("test1 - method 2");
            }
        };
    
        exports.test2 = {
            method1 : function () {
                console.log("test2 - method 1");
            },
    
            method2 : function () {
                console.log("test2 - method 2");
            }
        };
    
        return exports;
    });
    

    Then you can do:

    require(['test'], function (test) {
        var test1 = test.test1;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started out with a new site and I decided to use DOMImplementation
I just started getting this error today, seemingly out of nowhere. Any one see
i just started learning swings. And thought of trying out a simple program, but
I just started out with C and have very little knowledge about performance issues
I just started out using wordpress as a CMS. On the site I have
We have just started out with Team Foundation Server 2008 / Visual Studio Team
I have just started out with testing some php mvc framework In it, it
I've just started building a prototype application in Django. I started out by working
I have just started learning Erlang and am trying out some Project Euler problems
I've just started learning Lisp and I can't figure out how to compile 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.