From: Thomas 'PointedEars' Lahn on
VK wrote:

> Alex Shabanov wrote:
>> The question is why call transforms this to an object?
>
> Because you wanted it. call() sets the context of its first argument,

Nonsense.

> and it cannot be primitive value (string primitive in your case).

Correct.

> Javascript was originally made in the way to understand bad coding as
> long as it's possible, with an armee of non-professional programmers
> in mind.

Nonsense.

> So instead of throwing illegal argument error, it wraps
> string primitive into String object and works with it. Obviously it
> doesn't affect the s string itself, it remains string primitive.

Correct.

>> It is also unclear why string literal in fact is not an instance of
>> String in ("asd" instanceof String) expression but it does a string
>> in call/apply method invocations.
>
> Again, in Javascript there are string primitives and string objects.
> By default string literals create string primitives:
> var s = "abc";
> To make a string object one needs to use constructor:
> var s = new String("abc");
> but it has little practical sense: Javascript will "upcast" primitives
> if needed and downcast when not needed anymore. Say
> var len = s.length
> it upcast and downcast s to get the length value - because string
> primitive has no properties or methods, only String object does.

True, except of "upcast" and "downcast" which are yet again products of your
vivid imagination, to put it politely.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
From: Alex Shabanov on
On May 13, 3:01 am, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> ...

Thanks all who answered. It is clear now.
From: Lasse Reichstein Nielsen on
Thomas 'PointedEars' Lahn <PointedEars(a)web.de> writes:

> Stefan Weiss wrote:
>
>> In ECMAScript 3, |this| is always an object. call() and apply() will
>> convert anything passed as the first argument (the "thisArg") to its
>> object form, except null and undefined:
>>
>> | If thisArg is null or undefined, the called function is passed the
>> | global object as the this value. Otherwise, the called function is
>> | passed ToObject(thisArg) as the this value.
>> (ECMA-262, 3rd edition, 15.3.4.4)
>
> ES5 specifies it differently, but to the same effect.

.... execept in strict mode functions, where the ThisBinding of function
need not be an object. (10.4.3, step 1).

/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'