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 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

my regular Expressions are pretty bad so I thought would look for some help
The regular expression which I have provided will select the string 72719 . Regular
My regular extression (regex) is still work in progress, and I'm having the following
the regular languages are closed under the operation: init(L) = the set of the
since regular exressions are not supported in Cocoa I find RegexKitLite very usefull. But
What regular expression should I use to detect is the text I want to
Using regular expressions (in any language) is there a way to match a pattern
Are regular expressions used directly in compilers to identify tokens?
I have regular expression like this: error 1|error 2|error 3|error 4|error 5 about 80
My iphone app uses regular expressions (with NSRegularExpression) to perform calculations over a very

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.