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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:25:16+00:00 2026-05-31T18:25:16+00:00

I trying to use the module pattern with JS. But when I call HM.init()

  • 0

I trying to use the module pattern with JS. But when I call HM.init() in the console, it says undefined. It’s like this.carousel doesn’t exist at all. Why is that?

JS:

(function(window, $){

    var HM = (function (HM) {

        HM.init = function(){
            this.carousel.init();
        }

        return HM;

    })(HM || {});

    window.HM = HM;

    $(function(){
        console.log(HM.init()); // this doesn't work
    });


})(window, jQuery);

//Extending module (this is supposed to be in another file)
(function(window, HM, $){
    HM.carousel = {
        init: function(){
            return 'initialise HM';
        }
    }
})(window, HM, jQuery);.

Many thanks

  • 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-31T18:25:18+00:00Added an answer on May 31, 2026 at 6:25 pm

    The reason it prints undefined is because HM.init doesn’t return anything (no return statement, so it defaults to returning undefined).

    Either you want to add return before the call to this.carousel.init(), like so:

    ...
    HM.init = function(){
        return this.carousel.init();
    }
    ...
    

    …or you want to use console.log instead inside your HM.carousel.init function, if you want to print ‘initialise HM’ to the console:

    ...
    HM.carousel = {
        init: function(){
            return 'initialise HM';
        }
    }
    ...
    

    (the return value in itself isn’t a good debugging tool, so it probably makes more sense to print it with console.log.)

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

Sidebar

Related Questions

I am trying to use this python module HTML.py but GAE gives me ImportError:
I'm trying to use Haskells Data.Heap module, but I'm incapable of even using it
I'm trying to use Asp.NET WebAPI module but I get a weird error. When
I'm trying to understand js module patterns in use with jQuery. I've edited this
I am trying to use the JavaScript Module Pattern and I run into a
I'm trying to use the Tenjin module but it fails because it can't find
I'm trying to use the multiprocessing module in python 2.6, but apparently there is
I'm trying to use the win32gui module included with pywin32 but I can't get
I'm trying to use the timeit module but I don't know how. I have
I have been trying to use the Perl utility/module "prove" as a test harness

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.