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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:38:19+00:00 2026-05-27T05:38:19+00:00

I discovered a peculiarity in JavaScript (or perhaps my browser’s idea of it): var

  • 0

I discovered a peculiarity in JavaScript (or perhaps my browser’s idea of it):

var s = "Hello, world";

function foo(arg)
{
    console.log(arg);
    console.log(this);
}

foo.call(s, s);

Running the above with Firebug console enabled, I get:

Hello, world
String { 0="H", 1="e", more...}

Why does the string automatically get turned into a weird object before becoming the this passed to foo ?

The reason I call it a weird object is because jQuery chokes on it. For example:

$.each(["one", "two", "three"], function(i, x) {
    $('<p></p>').text(x)   .appendTo('body'); // Works
    $('<p></p>').text(this).appendTo('body'); // Doesn't work
});
  • 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-27T05:38:20+00:00Added an answer on May 27, 2026 at 5:38 am

    this is coerced into an object, i.e. Object("test") is internally called.

    (function() {
        return this;
    }).call("test");
    
    // returns same as `new String("test")` or `Object("test")`
    

    if the method is a function in non-strict mode … primitive values will be boxed*.

    Note that using strict mode indeed does return the primitive value:

    (function() {
        "use strict";
        return this;
    }).call("test") === "test"; // true
    

    * Boxing a value of a value allocates an object instance and copies the value into the new object.

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

Sidebar

Related Questions

I recently discovered you can compile JScript into console apps using a built in
I discovered a method of extending the core jQuery init function (which is what
I discovered that the dojox.charting.action2d.Tooltip takes a custom function to provide the text for
I discovered something very strange that I'm hoping to better understand. var all =
Just discovered something rather funny: var Queue : TQueue <TProc>; MyProc : TProc; ...
I discovered, when Firefox's JSON.stringify function converts string with line breaks it converts '\n'
Having discovered that IE does not handle javascript onmouseout , I'm determined to use
Discovered a strange problem that went undetected because I do 99% of my web
Discovered something and am looking into a bit of incite as to why one
Just discovered an issue with the sorting plugin used on our cart, was working

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.