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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:14:49+00:00 2026-06-14T09:14:49+00:00

How can I rewrite a function that is in the form: foo = function(arg1,arg2){….};

  • 0

How can I rewrite a function that is in the form:

 foo = function(arg1,arg2){....};

into a form such that arg1 becomes the receiver, to be used like the following?

arg1.foo(arg2);

Edit
I found out that with jQuery, I can do this.

jQuery.fn.foo = function(arg){
  ...
}

What is the way to do this with Javascript not using jQuery?

  • 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-06-14T09:14:50+00:00Added an answer on June 14, 2026 at 9:14 am

    The objects that jQuery returns are jQuery objects, not DOM objects. They contain collections of DOM objects, but jQuery does not directly add any methods to DOM objects at all. jQuery.fn is simply a reference to the prototype of the objects returned by jQuery, allowing you to add methods to that prototype directly.

    Since you’re interested in reproducing jQuery’s behavior, you could do the same: wrap native DOM objects in a class of your own, adding whatever methods you want to that wrapper class. Note that you cannot call just any DOM object method on a jQuery instance; jQuery defines some utility methods for invoking actual DOM methods, but in order to call many other DOM methods, you need to access the real DOM objects wrapped inside the jQuery instance. You will have the same limitation with your custom wrapper class — you will need to implement methods on your wrapper that forward the call to the underlying DOM object.

    Example:

    function DOMWrapper(domObject) {
        this.domObject = domObject;
    }
    
    DOMWrapper.prototype = {
    
        constructor: DOMWrapper,
    
        foo: function(arg1, arg2, arg3) {
            // this.domObject refers to the wrapped object here
            this.domObject.nativeMethod();
            // you could do things like this here:
            return this.bar.call(this.domObject, arg1, arg2, arg3);
        },
    
        bar: function(arg1, arg2, arg3) {
            // now, even though "bar" is defined as a method of
            // the DOMWrapper prototype, it has been invoked by "foo"
            // in the context of the wrapped DOM object, so
            // "this" refers directly to the DOM object in this method
    
            // this goes to the actual DOM nativeMethod:
            return this.nativeMethod();
        },
    
        domMethodWrapper: function() {
            return this.domObject.nativeMethod();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In javascript, you can rewrite a function, like so: function foo() { setTimeout(function() {
How can I rewrite this code to coffeescript: $('.delete_action').click(function(event) { $.get('/delete_action?name=' + event.target.name +
How can I rewrite Apple's GLCameraRipple example so that it doesn't require iOS 5.0?
How can i rewrite all external links with a single onmousedown event? Kinda like
Suppose that I have a simple form in my page like this : <form
Can someone rewrite this javascript. The problem now is that 1 regex is only
Possible Duplicate: How can I use PHP closure function like function() use() on PHP
I'm getting to grips with D3.js. I would like to write a function that
I'm writing something that will examine a function and rewrite that function in another
how I can rewrite this: for (int i = 0; i < numberOfSpaces; i++)

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.