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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:57:26+00:00 2026-05-18T23:57:26+00:00

I’ve a question about this reserved word in JavaScript. Check out codes below: Function.prototype.method

  • 0

I’ve a question about this reserved word in JavaScript.

Check out codes below:

Function.prototype.method = function (name, func) {
    if (!this.prototype[name]) {
        this.prototype[name] = func;
    }        
};

String.method('deentityify', function () {

    var entity = {
        quot: '"',
        lt: '<',
        gt: '>'
    };

    return function () {

        /*if (this === String.prototype) {
            alert('true');
        } else {
            alert('false');
        }*/

        return this.replace(/&([^&;]+);/g,
            function (a, b) {
                var r = entity[b];
                return typeof r === 'string' ? r : a;
            }
        );
    };
}());

document.write('&lt;&quot;&gt;'.deentityify());

You can edit codes above at: http://jsfiddle.net/G3Tkm/

My question is:

What is the this reserved word at line 27 return this.replace(/&([^&;]+);/g, is?

I guess: this === String.prototype, but it isn’t.

The type of '&lt;&quot;&gt;' is string, and type of this is object. So this !== '&lt;&quot;&gt;'

Thank you very much!

  • 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-18T23:57:27+00:00Added an answer on May 18, 2026 at 11:57 pm

    Whenever I find a this keyword in JavaScript code I usually just look upwards, until I find the surrounding function it’s in.

    Then I try and understand how this function gets called from the outside. This is important because the value of this changes based on how the function is being called.

    From your code it seems that String.method()‘s job is to add methods to the prototype chain of the String object. This is something that you shouldn’t really do, it’s sort of bad JavaScript behavior and might cause some issues later on.

    However, for the sake of an explanation, whenever you call the deentityify method on a string, such as "foo".deentityify() – suppose this calls whatever you assigned in String.method('deentityify', function () { – this becomes in effect another function itself (if String.method works as I think).

    So, when using "foo".deentityify()() your this will refer to the caller, which is "foo".deentityify(). And the caller of "foo".deentityify() is in fact "foo" itself.

    So basically this, in your case, refers to the String object you’re calling the method from.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I need to clean up various Word 'smart' characters in user input, including but
I have just tried to save a simple *.rtf file with some websites and
I am currently running into a problem where an element is coming back from

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.