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

  • Home
  • SEARCH
  • 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 6374929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:32:57+00:00 2026-05-25T01:32:57+00:00

I have been studying a jQuery plugin. The plugin extends $.fn as you would

  • 0

I have been studying a jQuery plugin. The plugin extends $.fn as you would expect. However the plugin also defines an object for it’s use. The object is defined like so..

$.MyObj = function() {

}

$.MyObj.prototype.foo = "green";

Why would you make the object definition a property of $ ? Why not just define the object globaly?

MyObj = function() {

}

MyObj.prototype.foo = "green";

Are there any benefits to making the object definition a property of $ ?

  • 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-25T01:32:57+00:00Added an answer on May 25, 2026 at 1:32 am

    General Plugin Convention

    A good plugin designer will typically create a very small global footprint. If a reusable object or function is being provided, it needs to be accessible from somewhere.

    Typically this is done by adding a single global object that contains the necessary functions (or is the necessary function).

    Example: If a plugin foo.js is being added to the page, you can expect it to add

    window.foo = {};
    //or
    window.foo = function(){};
    

    It would be silly of any developer to use two scripts /path/to/foo.js and /different/path/to/foo.js and expect them to work nicely together, as they likely share the same namespace.

    With jQuery plugins, however, the plugins require jQuery. As such there is no reason to pollute the global namespace when you can guarantee that the jQuery object exists.

    As (by definition) jQuery plugins require jQuery, the suggested naming convention for a plugin is jQuery.[plugin name].js. Just like normal plugins, it would be silly for a developer to use two scripts /path/to/jQuery.foo.js and /different/path/to/jQuery.foo.js and expect them to work nicely together.

    jQuery nuances

    Some jQuery plugins extend $.fn[pluginName], others are extra functions (like $.each, $.ajax, and $.extend), and a bunch extend jQuery’s selector capabilities. Each of them often require globally persistent data, be it default values, utility functions or what-have-you.

    A plugin that creates $.fn.foo might also want $.foo.defaultSettings to be persistent and extensible.

    As far as advantages go, adding jQuery plugins to the jQuery object reduces global pollution, and I don’t know anyone who likes pollution.

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

Sidebar

Related Questions

i have been recently studying php and mysql and also is currently developing a
Have been studying the file system related classes of Adobe AIR 1.5, but so
I have been studying SOAP and WSDL in preparation for implementing a web service.
I have been studying DDD in-depth on my own time; reading everything about it
I have been studying unicode and its Python implementation now for two days, and
Recently I have been studying recursion; how to write it, analyze it, etc. I
Over the last few weeks I have been studying the MVC design pattern for
I am trying to teach ASP.NET MVC to students (undergrads) that have been studying
I've been studying OOP for quite a while now and I have a good
I've recently been studying TDD, attended a conference and have dabbled in few tests

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.