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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:48:19+00:00 2026-06-09T11:48:19+00:00

In node.js, instead of : dummy = require(‘dummy’) dummy.aMethod() dummy.anotherMethod() I want to use

  • 0

In node.js, instead of :

dummy = require('dummy')

dummy.aMethod()
dummy.anotherMethod()

I want to use directly the methods in my context :

dummy = require('dummy')
loadMethods(dummy)

aMethod()
anotherMethod()

How can I implement the function loadMethods ?

  • 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-09T11:48:21+00:00Added an answer on June 9, 2026 at 11:48 am

    One thing you can do is to use with, like this:

    with (dummy) {
      aMethod();
      anotherMethod();
    }
    

    That’s not recommended though, as it makes a lot of things ambiguous and not behaving as you would expect them to.

    To do exactly what you’re asking for, you can add these methods to the global object. You can use something like this:

    for (var prop in dummy) {
      if (dummy.hasOwnProperty(prop)) {
        global[prop] = dummy[prop];
      }
    }
    

    This approach has its limitations too, though – for example, you can’t use aMethod() in the body of a function, the this object will be wrong (of course, you could use bind to keep it correct). Also, global is not really global, but module-scoped – so every module gets its own global object.

    So, weighing the options, you should probably stick with using the methods through dummy. This way you’ll always get the expected behavior (this will be dummy) and you’ll have a clear indication that the methods you’re using are actually implemented in the dummy module and use its state. Find a good IDE and typing shouldn’t be a problem.

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

Sidebar

Related Questions

http://jsfiddle.net/J2KuY/ In test2, you can see that instead of removing the node from the
This question follows a previous one: Shall I use Node.js Instead of Rails for
Can node.js be setup to recognize a proxy (like Fiddler for example) and route
Is there anyway I can customize the paths to a node's tabs? When using
Instead of asking for help when hitting the iceberg, now I can see there
Is there a way to apply XPath's starts-with function to a node's name instead
I want to check the node of the selected text. If it is span,
I want to extend the Nokohiri::XML::Node object into my own unique object with custom
I want to search for an XML nodes value without knowing the node's parent.
Can someone tell me the exact difference between node() and element() types in XQuery?

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.