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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:50:19+00:00 2026-05-21T11:50:19+00:00

I am trying to cut down jQuery to a very specific set of functions

  • 0

I am trying to cut down jQuery to a very specific set of functions to use in a product (as well as my general learning). Looking through the source, this seems to be the main structure behind the jQuery library. And it works fantastically.

The big part i can’t get my head around, is how jQuery can return an element array, as well as retaining the jQuery object.

Ie, $(“body”) will return the body in an array, but i can still say $(“body”).hide() (so i’m essentially calling ‘hide’ on an array?)

The question: How can I return both an Array AND the jQuery object created in the first function?

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

var $$ = MyNewLibrary;

MyNewLibrary.fn = MyNewLibrary.prototype = 
{
    el: null,
    length: 0,
    selector: "",
    init: function (selector, context) 
    {
        var elem;
        elem = document.getElementById(
                selector[0].substr(1, selector[0].length));

        if (elem) 
        {
            this.length = 1;
            this[0] = elem;
        }

        this.context = document;
        this.selector = selector;
        return this;

    },

    //Example of chained function
    Html: function (str) {
        if (typeof str == "string") {
            this[0].innerHTML = str;
        }
        if (typeof str == "undefined") {
            return this[0].innerHTML;
        }
        return this;
    }

};

MyNewLibrary.fn.init.prototype = MyNewLibrary.fn;

MyNewLibrary.BasicFunction = MyNewLibrary.fn.BasicFunction  = function () 
{
    return "A string returned by $$.BasicFunction()";
};
  • 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-21T11:50:20+00:00Added an answer on May 21, 2026 at 11:50 am

    An array is an object, and an object can have functions, so through transitivity, arrays can have functions. If there are multiple results, keep adding them to the newly created object of your library.

    this[0] = element1;
    this[1] = element2;
    // and so on
    

    It’s not exactly an array but an array-like object, with a length property and corresponding numeric indexes. jQuery doesn’t return an array either, which can be tested with

    $("<some selector>") instanceof Array; // false
    

    However, jQuery always returns this array-like object, even when selecting an element by id. In that case an array-like object (the jQuery object) is returned with a single element in it.

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

Sidebar

Related Questions

I'm trying to use delegates to cut down on my code in this project.
Im on an optimization crusade for one of my sites, trying to cut down
I am trying to cut over an existing WebForms app to use Routing, and
I'm trying to use Unix cut to remove the first two fields per line.
I am trying to cut down the number of ports printed in this list:
I am working on a modularized Flex application, and I am trying to cut-down
Im trying to cut down some code, basically the following click event is used
I am trying to use jQuery's .data() tool in a jQuery plugin but I'm
I'm trying to find ways to cut down memory usage for my app right
I'm trying to take a {variable} string and cut it down for entry into

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.