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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:05:08+00:00 2026-06-05T04:05:08+00:00

I am considering using RequireJS to organize my scripts into modules. Basically, each of

  • 0

I am considering using RequireJS to organize my scripts into modules.

Basically, each of my scripts define a class var MyScript = Class.create({...}) (except the scripts in ext/ which are third-party libraries).

Taking a real-world example, how would I be able to organize those imports as modules?

<script type="text/javascript" src="js/ext/prototype.js"></script>
<script type="text/javascript" src="js/ext/scriptaculous.js"></script>
<script type="text/javascript" src="js/ext/effects.js"></script>
<script type="text/javascript" src="js/ext/carousel.js"></script>
<script type="text/javascript" src="js/lib/sanityChecker.js"></script>
<script type="text/javascript" src="js/lib/logger.js"></script>
<script type="text/javascript" src="js/ext/modernizr.js"></script>
<script type="text/javascript" src="js/lib/localStorageChecker.js"></script>
<script type="text/javascript" src="js/lib/domNavigationUtils.js"></script>
<script type="text/javascript" src="js/lib/externalLinkDetector.js"></script>
<script type="text/javascript" src="js/lib/gondola.js"></script>
<script type="text/javascript" src="js/pages/common.js"></script>
<script type="text/javascript" src="js/pages/homepage.js"></script>

I fail to understand what I should pass as an argument for my modules depending on Prototype (basically, every one of them).

Thanks in advance for your help !

Rolf

  • 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-05T04:05:11+00:00Added an answer on June 5, 2026 at 4:05 am

    In your situation it would be a two step process:

    1. Use the requirejs shim to load third party libraries that aren’t AMD compatible
    2. Modify your existing classes to use define

    For third party libraries that are not AMD compatible (such as Prototype) you will need to setup shim properties

    An example of that might be:

    require.config({
        baseUrl: 'scripts/',
        paths: {
            'prototype': 'lib/prototype',
            'scriptaculous': 'lib/scriptaculous'
        },
        shim: {
            'prototype': {
                // Don't actually need to use this object as 
                // Prototype affects native objects and creates global ones too
                // but it's the most sensible object to return
                exports: 'Prototype'
            },
            'scriptaculous': {
                deps: ['prototype'],
                exports: 'Scriptaculous'
            }
            // Add more third party libs/plugins and their dependencies
        }
    });
    

    For the Classes that you write you can use a pattern like the following:

    classes/SomeClass.js

    // Sugar syntax - http://requirejs.org/docs/whyamd.html#sugar
    define(function(require){
        require('prototype'); // Ensure Prototype is present
    
        return Class.create({
            initialize: function(name) {
                console.log('name');    
            }
        })
    });
    

    Should you need to extend any of your existing classes just require those as well and assign them to a variable.

    And to use it, just require the class from the page that needs it:

    page.js

    require(['classes/SomeClass'], function(SomeClass){
        new SomeClass('john'); // logs 'John'
    });
    

    Using the shim config option will allow you to use any non-AMD scripts without needing to modify them.

    One final note, Modernizr is not intended to be used as an AMD module as that script needs to run synchronously. So don’t include that!

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

Sidebar

Related Questions

I am considering using a character with a diacritical mark (e.g., ō) in a
I am considering using Firebase for an application that should people to use full-text
I'm considering using CouchBase for a very read heavy and write heavy application. I'll
I'm considering using a TVar to store some state in a web application (that
I'm considering using a message queue-like system as the backend for a web application
I'm considering using the Google Contacts API for a webapp, but I'm worried that
I'm considering using memcached (at some point) in my application i'm currently developing. Eventually,
I'm considering using Grails for my current project. I have a couple of requirements
I am considering using something like StackFrame stackFrame = new StackFrame(1) to log the
I am considering using ClickOnce for a legacy Windows Forms application. I have several

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.