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

The Archive Base Latest Questions

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

I am implement following this. //to_s.js (function(){ String.prototype.to_s = function(){ var str = this.toString();

  • 0

I am implement following this.

//to_s.js
(function(){
String.prototype.to_s = function(){
        var str = this.toString();
        var convert = function(s){
            return eval(s);
        };

        while(/#{(\w+)}/.test(str)){

            // bad  because I use eval...

            var matchStr =RegExp.$1;

            var str = str.replace(/#{(\w+)}/,convert(matchStr));

        }
        return str;
    };
})();

module.exports = String.prototype.to_s;


// test/to_s_test.js

require("./../to_s");

var name = 33;

"hello #{name}".to_s();

I run to_s_test.js, but it happend error that ‘name is undefined’.But I don’t know why it happen.But change ‘var name = 33’ to name = 33 , It works… Do you have any idea? Thanks in advance.

  • 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:30:44+00:00Added an answer on June 9, 2026 at 11:30 am

    It will only work without var because eval occurs in another context, and therefore only globals may be accessed using your method. A global is automatically created when you do not declare the variable; however, in node.js, variables declared in modules are not global.

    This is why, as I previously mentioned, attempting to make languages conform to other languages’ idioms is a bad idea.

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

Sidebar

Related Questions

I'm following this how-to to implement Core Data storage in my app: I have
I am trying to implement an autocomplete in ASP.NET MVC 3, following this post
I get an error at adapter.getFilter().filter(s) in the onTextChanged() function. I was following this
I'm trying to implement a generic function that generates a std::string from an id
I am learning and using Web API and need to implement following Authentication mechanism
In an application having UITabBarController , I want to implement following scenario: When user
I need to implement the following: There is a table A which is supposed
How do I implement the following relationship using JPA? table person ( id int,
we need to implement the following query in such a way that we should
I want to implement the following constraints in mysql: create table TypeMapping( ... constraint

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.