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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:07:16+00:00 2026-06-11T07:07:16+00:00

My question is rather weird, it has to do with something i have seen

  • 0

My question is rather weird, it has to do with something i have seen in jQuery but so far i have been unable to recreate it.

in jQuery you can go like this

jQuery('div').append

or

jQuery.ajax

the application i am making would need a similar syntax, i notice if you use new like

var that=new function(){
}

you can call the function with just that, without the (), but in some cases i would need it.

The reason for this is some functions i have need to select a dom element just like jQuery so.

that('[data-something="this"]').setEvent('click',functin(){})

and some automatically do it so:

that.loadIt('this','[data-something="that"]') 

the reason for this is that the dom elements are loaded externally and pushed, then the script waits for it to be ready before continuing. and doing it this way, to me anyway seems like the most cleanest way to get this functionality (i am coding a full javascript framework so i avoid libraries to keep the scripts fast)

  • 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-11T07:07:18+00:00Added an answer on June 11, 2026 at 7:07 am

    Functions are objects.

    Just get rid of new, and add properties directly to that.

    var that = function() {
        // do some work
    }
    
    that.loadit = function() {
        // do other work
    }
    

    Since you’re trying to achieve something like jQuery does, then have that call a constructor.

    ;(function(global) {
    
           // function to be publicly exposed
        var that = function(foo, bar) {
            return new MyLibrary(foo, bar);
        }
    
           // publicly expose the function
        global.that = that;
    
           // use the function as a namespace for utilities
        that.loadit = function() {
            // do other work
        }
    
           // The actual constructor function, like the internal jQuery constructor
        MyLibrary(foo, bar) {
            // constructor function
        }
    
           // Prototypal inheritance of objects created from the constructor
        MyLibrary.prototype.setEvent = function() {
            // do some work
            return this;  // allows for method chaining
        };
        MyLibrary.prototype.otherMethod = function() {
            // do something else
            return this;  // allows for method chaining
        };
    })(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather small but weird problem that I can't seem to fix.
I have another Richfaces question which may seem rather weird. I am developing a
my question is rather simple, if you have an pure virtual class (interface) but
Have a rather simple question. Does anyone knows if i can use jparallax both
It may seems rather newbie question, but can you explain why method Der.B() cannot
I have been perpetually intrigued by test-driven development, but I can never follow through
I most likely have the same problem as in this question: Weird Chrome prototype/jQuery
Excuse if this is more a file format conversion question rather than programming, but
The question is rather straightforward but not answered by searching. How do I determine
My question might sound rather strange, but still I didn't find any reference and

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.