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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:02:11+00:00 2026-05-28T00:02:11+00:00

What is the best way to implement module pattern, while the module code depends

  • 0

What is the best way to implement module pattern, while the module code depends on third party libraries like jQuery for example?

var someModule = (function(){
    //private attributes
    var privateVar = 5;

    //private methods
    var privateMethod = function(){
        return 'Private Test';
    };

    return {
        //public attributes
        publicVar: 10,
        //public methods
        publicMethod: function(){
            return ' Followed By Public Test ';
        },

        //let's access the private members
        getData: function(){
            //make ajax call and do some processing and generate output
            return privateMethod() + this.publicMethod() + privateVar;
        }
    }
})(); //the parens here cause the anonymous function to execute and return

someModule.getData();

My question is: I am planning to put all the code in a library like fashion in a javascript file.

As you see in the getData() method, I plan to make ajax calls. I want to use jQuery library for this. Now how do I code a javascript module, while relying on jQuery ?

Should I make my whole library a jQuery plugin instead?

  • 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-28T00:02:12+00:00Added an answer on May 28, 2026 at 12:02 am

    A great tutorial/example can be found here or here. I know this isn’t the module pattern, but it offers the same benefits of the revealing module pattern along with allowing you to extend the namespace across files if needed. Below is the code from that example.

    //Self-Executing Anonymous Func: Part 2 (Public & Private)
    (function( skillet, $, undefined ) {
        //Private Property
        var isHot = true;
    
        //Public Property
        skillet.ingredient = "Bacon Strips";
    
        //Public Method
        skillet.fry = function() {
            var oliveOil;
    
            addItem( "\t\n Butter \n\t" );
            addItem( oliveOil );
            console.log( "Frying " + skillet.ingredient );
        };
    
        //Private Method
        function addItem( item ) {
            if ( item !== undefined ) {
                console.log( "Adding " + $.trim(item) );
            }
        }    
    }( window.skillet = window.skillet || {}, jQuery ));
    
    //Public Properties
    console.log( skillet.ingredient ); //Bacon Strips
    
    //Public Methods
    skillet.fry(); //Adding Butter & Frying Bacon Strips
    
    //Adding a Public Property
    skillet.quantity = "12";
    console.log( skillet.quantity ); //12
    
    //Adding New Functionality to the Skillet
    (function( skillet, $, undefined ) {
        //Private Property
        var amountOfGrease = "1 Cup";
    
        //Public Method
        skillet.toString = function() {
            console.log( skillet.quantity + " " + 
                         skillet.ingredient + " & " + 
                         amountOfGrease + " of Grease" );
            console.log( isHot ? "Hot" : "Cold" );
        };    
    }( window.skillet = window.skillet || {}, jQuery ));
    
    try {
        //12 Bacon Strips & 1 Cup of Grease
        skillet.toString(); //Throws Exception
    } catch( e ) {
        console.log( e.message ); //isHot is not defined
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to implement the page view counter like the ones
Whats the best way to implement rollover 'buttons' like Stackoverflow has for 'Questions', 'Tags',
What is the best way to implement a three item hashMap? For example, I
What is the best way to implement an external module system for a DELPHI
What is the best way to implement, from a web page a download action
What is the best way to implement mutliple Default Buttons on a ASP.NET Webform?
What's the best way to implement the enum idiom in Ruby? I'm looking for
What's the best way to implement user controls that require AJAX callbacks? I want
What's the best way to implement a classic curry function in actionscript with a
What's the best way to implement Meebo-style floating windows? I'd prefer to use Prototype

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.