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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:51:03+00:00 2026-06-14T21:51:03+00:00

Given two modules a and b . I know that it is possible to

  • 0

Given two modules a and b. I know that it is possible to expose a‘s functionality to another module using the module.exports. I probably do not use it correctly.

a.js

function A() { ... }
A.prototype.func = function() { ... }

function test() {
    new A().func();
}

test();
module.exports = {
    A : new A()
};

The test() is working correctly. But the following breaks:

b.js

var A = require("./a");
A.func(); //throws an exception

How do I export the whole A module with its functionality?

Update: executing console.log(A) over b (as a second line), does not reveal any of A‘s methods and variables.

  • 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-14T21:51:05+00:00Added an answer on June 14, 2026 at 9:51 pm

    Try this:

    module.exports = new A();
    

    You won’t be able to instantiate a new A in b, but it seems like that’s what you want.

    Edit:

    Or you could change b.js to:

    var A = require('./a');
    A.A.func();
    

    But this is likely not what you want.

    The idea is that whatever exports is will be what is returned from require. It’s exactly the same reference.

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

Sidebar

Related Questions

I'm working on a python script that needs to run between two given times.
Given two modules, main and x with the following contents: main: class Singleton(object): _instance
I'm trying to write a Node.js module, using C++, that wraps and exposes some
Given two data frames: C1<-c(3,4,4,4,5) C2<-c(3,7,3,4,5) C3<-c(5,6,3,7,4) DF<-data.frame(C1=C1,C2=C2,C3=C3) DF C1 C2 C3 1 3
Given two tuples of the same arity, how can I lexicographically compare them? It
Given two arrays, how to find the maximum element which is common to both
Given two sorted arrays of integers, a and b , and an integer c
Given two strings text1 and text2 : public SOMEUSABLERETURNTYPE Compare(string text1, string text2) {
Given two identical boost::variant instances a and b , the expression ( a ==
Given: two images of the same subject matter; the images have the same resolution,

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.