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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:04:59+00:00 2026-05-23T11:04:59+00:00

I had a thought to do something like this: (function(window, undefined){ $ = window.jQuery;

  • 0

I had a thought to do something like this:

(function(window, undefined){
    $ = window.jQuery;
    $(function(){
        // Do some stuff
    });     
})(this);

Would you consider this good practice or bad? Does it have any implications for when jQuery(document).ready() would fire?

  • 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-23T11:04:59+00:00Added an answer on May 23, 2026 at 11:04 am

    Only reason I’d say would be if you have some javascript to run before the DOM is ready, and you don’t want to pollute the global namespace.

    (function(window, undefined){
        var $ = window.jQuery;
    
        // create some variables and/or functions that shouldn't be global
        //    ...and do some work before the "ready()" fires
        var a = 'some value';
        function b() {
            // do some important stuff
        }
        var c = b();
    
        // Maybe set up a `.live()` handler, which doesn't rely on DOM ready.
        $('.someSelector').live( function() {
            // Some handler code.
            // This works before DOM is ready.
        });
    
        $(function(){
            // Your DOM ready code
        });     
    })(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem like a programming 101 question and I had thought I knew
I thought I had seen a bug report about this on the jQuery site,
I thought I had a pretty good handle on memory management for objective-c, but
I thought I had this figured out but it turns out I'm just deleting
I had a wild thought today. I've been discovering that my users like my
Alright, I thought I had this whole setTimeout thing perfect but I seem to
Suppose I had the following function: function alertMesg() { alert(This ok function alerts message!);
I am using local resource strings in ASP. My strings are something like This
OK, so I thought I had this licked by I was wrong. Basically, I
I had thought I could enumerate the types using IMetaDataImport.EnumTypeDefs and for each of

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.