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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:18:09+00:00 2026-05-17T08:18:09+00:00

Don’t be afraid to use any technical jargon or low-level explanations for things, please.

  • 0

Don’t be afraid to use any technical jargon or low-level explanations for things, please. I’m savvy enough with computer architecture and low-level programming languages to comprehend any optimizations or memory management techniques, as well as complex structures (classes, member variables, etc.)

My primary focus of code is web-based applications. I work with PHP a lot and I’ve been learning CSS quickly. Javascript is currently my bottleneck, however. I know enough Javascript to do just about anything sans frameworks (DOM manipulation, AJAX queries, etc.). I also know that I can make my code run quicker, optimize it for specific cases, and I can shrink the over-all size of my code (no external script to include) by manually coding everything. However for ease of reading by other programmers and for speed of coding I’m trying to learn at least one Javascript framework.

After reading through the documentation on a number of frameworks and looking at some tutorials, I preferred jQuery. It allowed for very powerful iterative code in a single line and it had a very small chance of global variable namespace collision. From what I could tell, the ONLY global variable declared is the $ variable and everything else happens within this namespace, and there were even ways to access the namespace without this variable if you wanted to have two frameworks side-by-side. It also had a very small file to include (24 kilobytes gzipped) which means less server load.

My question is what are good practices in creating a jQuery plugin? If I were to start coding websites in jQuery, how should I go about it for the best interoperability and design? I want to ensure that my code can run along-side any other jQuery without interference, it’s possible to build plugins off of my code, and I minimize use of the jQuery namespace so that I don’t steal variables that might be used by another script.

  • 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-17T08:18:09+00:00Added an answer on May 17, 2026 at 8:18 am

    Read the jQuery plugin authoring suggestions, also look at the unminified jQuery. Notice the last line: window.jQuery = window.$ = jQuery; So there are two global variables window.jQuery and window.$. To delve into this issue a little deeper, read more about the documentation on using jQuery with other libraries and jQuery.noConflict():

      // Trigger no conflict mode.
    $.noConflict();
      // Code that uses other library's $ can follow here.
    

    For writing plugins, make sure to pay special attention to the section called Maintaining Chainability (since jQuery makes use of chainability so nicely). You have to explicitly return this in your plugins to maintain chainability. Additionally, speaking of clashing with other variables, make sure you stop your plugin from clashing with other code by using a closure:

      // Use a closure so you can use the dollar sign in your plugin, 
      //   but you don't clash with other uses of the dollar sign in the script
      //   around where you define your plugin (other libraries, etc.)
    (function( $ ){
    
        // Adding your plugin to jQuery
      $.fn.yourPlugin = function() {  
    
          // Maintain chainability
        return this.each(function() {
    
          // ...
    
        });
    
      };
    }( jQuery ));
    

    There’s a lot of other great information on that plugin authoring page. The above is just the bare bones. There’s info on defaults and options, namespacing, and many other things.

    Also, if you’re concerned about your variables clashing, you can also make use of closures for you own “regular” code… not just jQuery plugins. To do this, enclose your script in a self invoking anonymous function:

    (function() {
        var ...  // these vars will not clash with 
                 // anything outside this anonymous function
    
        // You can do your jQuery in here if you need to access
        //   the local vars:
        $(function() { ... });
    
    }());
    

    For example:

    // global 'clash'
    var clash = "test";
    
    (function() {
        // local 'clash'
        var clash = "something else";
        // this 'clash' shadows but doesn't change the global 'clash'
    }());
    
    alert(clash);
    // The global 'clash' has stayed unaffected by the local `clash`
    // Output: test
    

    jsFiddle example

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

Sidebar

Related Questions

No related questions found

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.