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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:38:57+00:00 2026-06-04T17:38:57+00:00

I am creating an attribute in a javascript object by replacing some strings in

  • 0

I am creating an attribute in a javascript object by replacing some strings in an existing object, as a side effect I want to make some additional changes to a third property, which I try to access with this.property however in the replace function this is referring to the window instead of my ‘master’ object. How can I pass in the encapsulating object, so that I can use this to access third property.

b = {
    a: 'onetwothree',
    count: 0,
    rp: function () {
        this.c = this.a.replace(/e/g, function (str, evalstr) {
            this.count++; // <-- this is refering to window.
            return 'e' + this.count
        })
    }
};
b.rp();

b.c = 'oneNaNtwothreNaNeNaN whereas I want it to be one1twothre2e3

  • 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-04T17:38:59+00:00Added an answer on June 4, 2026 at 5:38 pm
    rp: function () {
        this.c = this.a.replace(/e/g, function (str, evalstr) {
            this.count++;
            return 'e' + this.count
        }.bind( this )) // <-- bind the function
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to associate a JavaScript object with an HTML element. Is there a
I want to make a constructor function that creates a documentElement object. As an
When creating a libsvm training file, how do you differentiate between a nominal attribute
I'm trying to force an inherited class to use a custom attribute. I'm creating
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a server-side socket will fail if I'm trying to use the same port
I'm creating a button dynamically using JavaScript and at the same time assigning attributes
Is there a way to convert markup string to node object in JavaScript? Actually
I noticed that some of developers in our team are creating long jQuery selectors
In my current project, I am creating a number of user controls, some of

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.