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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:01:17+00:00 2026-05-26T16:01:17+00:00

Instead of string it is object String.prototype.foo = function () { return this; };

  • 0

Instead of string it is object

String.prototype.foo = function () { return this; };
typeof "hello".foo() // object ???
"hello".foo().toString(); //hello 

it should return string instead i guess.

  • 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-26T16:01:17+00:00Added an answer on May 26, 2026 at 4:01 pm

    No. A real string ("hello", 'booya') is a primitive value – it doesn’t have any functions or anything. It’s just a value.

    When you do "string".foo, it turns into this:

    Object("string").foo
    

    Inside of foo, this points towards Object("string"), not the primitive value. Doing Object("string") turns it into an object, so typeof object === 'object'.

    If you want the “underlying” primitive, call valueOf:

    String.prototype.foo = function () {
        return typeof this.valueOf();
    }
    "meep".foo(); //string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This simple regex matching returns a string instead of an object on every browser
String.prototype.foo = {}; String.prototype.foo.bar = function() { //How can you reference the grandparent string?
I need to create a function like Douglas Crockford's String.supplant: if (typeof String.prototype.supplant !==
Instead of returning a common string, is there a way to return classic objects?
Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param)
I'm trying to use std::string instead of char* whenever possible, but I worry I
I want to replace only the first matching element in a string instead of
I see some people write: //wordList is List<string> wordList.ForEach(delegate(string word){ Console.WriteLine(word);}); instead of: foreach(string
Basically url escapes a string except uses '+' instead of '%20' for spaces.
When writing the string ¿ out using System.out.println(new String(¿.getBytes(UTF-8))); ¿ is written instead 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.