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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:50:56+00:00 2026-05-22T12:50:56+00:00

regular = ‘a string’; enriched = enrichString(regular); sys.puts(enriched); function enrichString(str){ //run str through some

  • 0
regular = 'a string';
enriched = enrichString(regular);
sys.puts(enriched);

function enrichString(str){
    //run str through some regex stuff or other string manipulations
    return str;
}

Right now it seems to be doing what I hoped it would do but I don’t know if its safe. Could this result in undefined sometimes? Do I need to do something like:

regular = 'a string';
enriched = enrichString(regular, function(data){sys.puts(data);});

function enrichString(str, cb){
    //run str through some regex stuff or other string manipulations
    cb(str);
}

Thanks for the help!

  • 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-05-22T12:50:57+00:00Added an answer on May 22, 2026 at 12:50 pm

    You only need callbacks if your making asychronous non-blocking calls.

    var string = "foo",
        new_string = enrich(foo);
    
    doStuff(new_string);
    

    Is safe if enrich is blocking. For example

    function enrich(str) {
        // do regex stuff with str
    
        // manipulate it
    
        return str;
    }
    

    is blocking so it’s safe to do this. Where as

    function enrich(str) {
        // get some data from the database.
    
        // store the string in a file.
    
        return str;
    }
    

    Uses non blocking IO and is not safe. What you want to do is this :

    function enrich(str, cb) {
        // get some data from the database.
    
        // store the string in a file.
    
        return cb(str);
    }
    
    var string = "foo",
        new_string = enrich(foo, function (str) {
            doStuff(new_string);
        });
    

    Notice that

    enriched = enrichString(regular, sys.puts(data));

    Does not work because your passing in the return value of sys.puts(data) as your function parameter (data is undefined aswell!)

    You need to pass in a function.

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

Sidebar

Related Questions

A regular function can contain a call to itself in its definition, no problem.
Is there a Regular Expression that can detect SQL in a string? Does anyone
What is a good regular expression that can validate a text string to make
Regular Expression for matching string like: <any_string>+<any_string>+<any_string>?
I am learning regular expressions and I am trying find this string day1otlk_XXXX.gif where
Because regular expressions scare me, I'm trying to find a way to remove all
Using regular expressions, what is the simplest way to fetch a websites HTML and
My regular expression needs to be able to find the strings: Visual Studio 2008
So regular expressions seem to match on the longest possible match. For instance: public
The regular code snippet of syncing data with sync framework is this: LocalDBSyncAgent syncAgent

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.