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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:55:32+00:00 2026-06-18T08:55:32+00:00

I have a module with a function which generates the value for a vaariable

  • 0

I have a module with a function which generates the value for a vaariable for a variable “stitcheBook”. I can see and use this value using a callback.

However, I want to have this value available to me as a module property. How can i achieve this?

Note: I wish the output of the _BookStitcher.stitchAllStories function to go into the _BookStitcher.stitchedBook property.

module.exports = _BookStitcher = (function() {

var db = require('../modules/db');
var stitchedBook = {};

var stitchAllStories = function(callback) {


    db.dbConnection.smembers("storyIdSet", function (err, reply) {
        if (err) throw err;
        else {
            var storyList = reply;
            console.log(storyList);
            // start a separate multi command queue
            multi = db.dbConnection.multi();
            for (var i=0; i<storyList.length; i++) {
                multi.hgetall('story/' + String(storyList[i]) + '/properties');
            };
            // drains multi queue and runs atomically
            multi.exec(function (err, replies) {
                stitchedBook = replies;
                // console.log(stitchedBook);
                callback(stitchedBook);
            });
        };
    });


};


return {
    stitchedBook : stitchedBook,
    stitchAllStories: stitchAllStories

}

})();

EDIT: to add: I know that I can actually set the value from outside by doing something like this;

_BookStitcher.stitchAllStories(function (reply) {
        console.log("Book has been stitched!\n\n")
        console.log("the Book is;\n");
        console.log(reply);
        _BookStitcher.stitchedBook = reply;
        console.log("-------------------------------------------------------------------------\n\n\n");
        console.log(_BookStitcher.stitchedBook);

});

I was wondering if there was a way of doing it from inside the _BookStitcher module itself.

  • 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-18T08:55:32+00:00Added an answer on June 18, 2026 at 8:55 am

    You could take advantage of how object references work in JavaScript, and assign it to a property:

    module.exports = _BookStitcher = (function() {
    
        var db = require('../modules/db');
    
        // CHANGE HERE
        var stitched = { book: null };
    
        var stitchAllStories = function(callback) {
            db.dbConnection.smembers("storyIdSet", function (err, reply) {
                if (err) throw err;
                else {
                    var storyList = reply;
                    console.log(storyList);
                    // start a separate multi command queue
                    multi = db.dbConnection.multi();
                    for (var i=0; i<storyList.length; i++) {
                        multi.hgetall('story/' + String(storyList[i]) + '/properties');
                    };
                    // drains multi queue and runs atomically
                    multi.exec(function (err, replies) {
                        // CHANGE HERE
                        stitched.book = replies;
                        // console.log(stitchedBook);
                        callback(replies);
                    });
                };
            });
        };
    
        return {
            stitched : stitched,
            stitchAllStories: stitchAllStories
        };
    
    }());
    

    So instead of having it inside _BookStitcher.stitchedBook, you’d have it at _BookStitcher.stitched.book.

    But that looks awful, and I’d never use it! You can’t know when the value will be available, it’s only safe to use it from the callback, when you’re sure it’s been set.

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

Sidebar

Related Questions

i have created a module with this among others this function in it: <?php
I have a CMS with a form-module, which generates an awful markup, that makes
I have a module job_post which installs job_post content type. In this module I
I have installed jpagen module in my system in play framework. Which successfully generates
So I have a common module which contains processing functions for numbers and types
In F# i have the function: module ModuleName let X (y: int -> unit)
I have a function (in a module) that returns IO (Maybe a) where a
So I have the following function in my drupal module. I want to submit
If you have: module A class B end end You can find B and
I have a module containing multiple global functions, and a global variable. The variable

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.