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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:32:48+00:00 2026-05-26T16:32:48+00:00

I need to build a small JavaScript library that would only be a couple

  • 0

I need to build a small JavaScript library that would only be a couple kilobytes in size. To that end I would like to use some of the design choices that jQuery has made so famous.

Below are the two shells I have so far, and I was wondering if someone could advise me as to which style would probably be a better design choice.

var jQuery, $;

(function() {

    jQuery = $ = function(selector, context)
    {
        return new JQuery(selector, context);
    };

    var JQuery = function(selector, context)
    {
        // ...
        return this;
    };

    jQuery.fn = JQuery.prototype = {
        example: function()
        {
                //...
            return this;
        }
    };

}());

There is also a slightly modified version of the jQuery shell.

(function(window, undefined)
{
    var jQuery = function(selector, context)
    {
        return new jQuery.fn.init(selector, context);
    };

    jQuery.fn = jQuery.prototype = {
        init: function(selector, context)
        {
            // ...
            return this;
        },
        example: function()
        {
            //...
            return this;
        }
    }

    jQuery.fn.init.prototype = jQuery.fn;
    window.jQuery = window.$ = jQuery;

})(window);

I would also like to know if I’m making any bad design choices with either of these. JavaScript is not my primary language so I would like to make sure I’m not doing anything incorrectly.

  • 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-26T16:32:49+00:00Added an answer on May 26, 2026 at 4:32 pm
    • using the name jQuery for a library, which is not, in fact, jQuery, is a pretty bad design choice in the first place.
    • the first example has no window prefix for the global variables, which is bad for readability and strict mode compliance
    • setting jQuery.prototype in the second example seems pointless
    • I would prefer the version where the constructor is a member of fn and thus accessible from outside
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to build a small web app that will ultimately need to be
I need to build a small database for a school project and I'd like
For homework, I need to build a small java application.The main goal is to
I need to build something that starts serving a H.264 encoded video to a
I need to build a C++ library to distribute among our customers. The library
I have a small project where I need just part of boost library, boost::regex
i have to build an small app in order to show some data from
I have some code in a javascript file that needs to send queries back
I need to build a OS, a very small and basic one, with actually
I need to build a SQLite table that will consist of the following columns:

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.