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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:43:25+00:00 2026-05-18T12:43:25+00:00

var f = function(o){ return this+:+o+::+(typeof this)+:+(typeof o) }; f.call( 2, 2 ); //

  • 0
var f = function(o){ return this+":"+o+"::"+(typeof this)+":"+(typeof o) };
f.call( "2", "2" );
// "2:2::object:string"

var f = function(o){ return this+":"+(typeof this)+":"+(typeof o); };
var x = [1,/foo/,"bar",function(){},true,[],{}];
for (var i=0;i<x.length;++i) console.log(f.call(x[i],x[i]));
// "1:object:number"
// "/foo/:object:object"
// "bar:object:string"
// "function () {\n}:function:function"
// "true:object:boolean"
// ":object:object"
// "[object Object]:object:object"

I see the same results in Chrome, Firefox, and Safari, so I assume it’s per the spec, but…why? And where in the spec is this defined? And why not for functions?

  • 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-18T12:43:26+00:00Added an answer on May 18, 2026 at 12:43 pm

    As defined in ECMA-262 ECMAScript Language Specification 3rd edition (see footnote), It’s based on the spec (Section 15.3.4.4):

    var result = fun.call(thisArg[, arg1[, arg2[, ...]]]);  
    

    Parameters

    thisArg

    Determines the value of this inside
    fun. If thisArg is null or undefined,
    this will be the global object.
    Otherwise, this will be equal to
    Object(thisArg) (which is thisArg if
    thisArg is already an object, or a
    String, Boolean, or Number if thisArg
    is a primitive value of the
    corresponding type). Therefore, it is
    always true that typeof this ==
    “object” when the function executes.

    Note in particular the last line.

    The crucial thing is that js primitives (string, number, boolean, null, undefined) are immutable, so a function can not be attached to them. Therefore the call function wraps the primitive in an Object so that the function can be attached.

    E.g.:

    Doesn’t work:

    var test = "string";
    //the next 2 lines are invalid, as `test` is a primitive 
    test.someFun = function () { alert(this); }; 
    test.someFun();
    

    Works:

    var test = "string";
    //wrap test up to give it a mutable wrapper
    var temp = Object(test);
    temp.someFun = function () { alert(this); };
    temp.someFun();
    

    (footnote) – as patrick dw noted in the comments, this will change in ECMA-262 ECMAScript Language Specification 5th edition when in strict mode:

    From Section 15.3.4.4:

    NOTE The
    thisArg value is passed without
    modification as the this value. This
    is a change from Edition 3, where a
    undefined or null thisArg is replaced
    with the global object and ToObject is
    applied to all other values and that
    result is passed as the this value.

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

Sidebar

Related Questions

var Dog = function() { var _instance = 'hello world'; return function() { console.log(this._instance);
Having an object like this: var a = { b: string, c: function(){ return
This is my object : var obj = { a:{ x:1 y:function(){return this.x //works
var x= 1; Number.prototype.test = function () { return this }; x.test() === x.test()
I find myself doing this repeatedy. $jq(button).filter(function(){ return this.id.match(/^user_(\d+)_edit$/); }).click(function(){ var matches = this.id.match(/^user_(\d+)_edit$/);
For example: (function() { var proxied = window.eval; window.eval = function() { return proxied.apply(this,
This seems like a straightforward implementation: ko.observableArray.fn.findEl = function(id) { return ko.computed(function() { var
$(a.close).click(function() { var id = $(this).attr(id); alert(id); $(this).parents(div.venue:first).fadeOut(Fast); return false; }); Any ideas why
searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == - 1) return;
I have a javascript function: string.prototype.startsWith = function(str) { return (this.indexOf(str) === 0); }

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.