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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:48:42+00:00 2026-06-02T23:48:42+00:00

I am porting one of my old javascript file to compatible with requireJS. This

  • 0

I am porting one of my old javascript file to compatible with requireJS. This is previously how the code looks like.

// effect.js
(function(exports){

    // shorthand
    exports.effect = function(selector) {
        return new Effect(selector);
    };

    // init
    exports.Effect = function(selector){
        this.target = document.getElementById(selector);        
    };

    Effect.prototype.run = function(){
        alert('halo');
    };
})(this);

//invoke it with
effect('box').run();

Tried to make it compatible with requireJS:

// effect.js
define(function(exports){   
    // Shorthand
    exports.effect = function(selector) {
        return new Effect(selector);
    };

    // init
    exports.Effect = function(selector){
        alert('halo');
        this.target = document.getElementById(selector);        
    };

    Effect.prototype.run = function(){
        alert('halo');
    };      
}

// require js
require([
    'effect.js'
],function(Effect){
    effect('box').run();
})

The code above won’t run, how do I achieve the same result with just running shorthand of effect(‘box’).run().

  • 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-02T23:48:43+00:00Added an answer on June 2, 2026 at 11:48 pm

    Give this a try:

    define(function() {
    
        // init
        var Effect = function(selector) {
            this.target = document.getElementById(selector);
        };
    
        Effect.prototype.run = function(){
            alert('halo');
        };
    
        // Replaces the 'shorthand' function from the first example 
        // This is returned as a module to the require call
        return function(selector) {
            return new Effect(selector);
        }
    
    });
    
    require(['effect.js'], function(effect) {
        effect('box').run();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm porting over some code from one project to another within my company and
I'm porting a cross-platform lib I use to Alchemy. One particular file has a
I'm porting a bit of an old code from C to C++. The old
I've just inherited an old WinForms app with a UI layout like this: I'm
I'm porting an old VB6 app into .Net but one Vb6 form is too
i am porting over a website from asp. i have one page that i
I'm porting a game from UT3 to UDK. One of the classes is a
Posting this one for a friend. They have an Icefaces app that uses Icefaces's
Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr);
I have an odd one - I am porting some data from one CMS

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.