This is an interesting question ... Thanks for the message!
Honestly, I am a little surprised Object(this), because JavaScript seems to force something on the object (using wrappers) in situations where it thiscould potentially be a primitive value.
this Function.prototype.bind(), JavaScript ( ):
var foo = function () {
console.log(this, typeof this);
}.bind('foo');
var bar = function () {
console.log(this, typeof this);
}.bind(1337);
var baz = function () {
console.log(this, typeof this);
}.bind(false);
var qux = function () {
console.log(this, typeof this);
}.bind(NaN);
var quux = function () {
console.log(this, typeof this);
}.bind(undefined);
var corge = function () {
console.log(this, typeof this);
}.bind(null);
var grault = function () {
console.log(this, typeof this);
}.bind([]);
var garply = function () {
console.log(this, typeof this);
}.bind({});
var waldo = function () {
console.log(this, typeof this);
}.bind(/regex/);
var fred = function () {
console.log(this, typeof this);
}.bind(function () {});
foo();
bar();
baz();
qux();
quux();
corge();
grault();
garply();
waldo();
fred();
this Function.prototype.call() Function.prototype.apply(), JavaScript :
Array.prototype.foo = function () {
console.log(this, typeof this);
};
['foo'].foo();
Array.prototype.foo.call('bar');
Array.prototype.foo.call(42);
Array.prototype.foo.call(true);
Array.prototype.foo.call(NaN);
Array.prototype.foo.call(undefined);
Array.prototype.foo.call(null);
Array.prototype.foo.call({});
Array.prototype.foo.call(/regex/);
Array.prototype.foo.call(function () {});
JavaScript , , , . Number, String Boolean :
var num = 1337,
str = '',
bool = true;
console.log(Number(str), typeof Number(str));
console.log(Number(bool), typeof Number(bool));
console.log(String(num), typeof String(num));
console.log(String(bool), typeof String(bool));
console.log(Boolean(num), typeof Boolean(num))
console.log(Boolean(str), typeof Boolean(str));
Hide resultObject():
console.log(typeof Object(false), Object(false) instanceof Boolean);
console.log(typeof Object('bar'), Object('bar') instanceof String);
console.log(typeof Object(42), Object(42) instanceof Number);
console.log(typeof Object(NaN), Object(NaN) instanceof Number);
console.log(typeof Object(undefined), Object(undefined) instanceof Object);
console.log(typeof Object(null), Object(null) instanceof Object);
console.log(typeof Object(['foo']), Object(['foo']) instanceof Array);
console.log(typeof Object({}), Object({}) instanceof Object);
console.log(typeof Object(/regex/), Object(/regex/) instanceof RegExp);
console.log(typeof Object(function () {}), Object(function () {}) instanceof Function);
Hide result, Object(this) this -. this , :
var obj1 = {baz: 'Baz'},
obj2 = Object(obj1);
var arr1 = ['foo', 'bar'],
arr2 = Object(arr1);
var reg1 = /regex/,
reg2 = Object(reg1);
var fun1 = function () { return 'Hello!'; },
fun2 = Object(fun1);
console.log(arr1 === arr2);
console.log(obj1 === obj2);
console.log(reg1 === reg2);
console.log(fun1 === fun2);
Hide result, Object , , , new :
var foo = Object('foo'),
bar = new Object('bar');
console.log(foo);
console.log(bar);
Hide result, , : , this , Object(this) . , , .
?
torazaburo : - ! , this ! , , Object(this)...
Function.prototype.bind()
var foo = function () {
'use strict';
console.log(this, typeof this);
}.bind('foo');
var bar = function () {
'use strict';
console.log(this, typeof this);
}.bind(1337);
var baz = function () {
'use strict';
console.log(this, typeof this);
}.bind(false);
var qux = function () {
'use strict';
console.log(this, typeof this);
}.bind(NaN);
var quux = function () {
'use strict';
console.log(this, typeof this);
}.bind(undefined);
var corge = function () {
'use strict';
console.log(this, typeof this);
}.bind(null);
var grault = function () {
'use strict';
console.log(this, typeof this);
}.bind([]);
var garply = function () {
'use strict';
console.log(this, typeof this);
}.bind({});
var waldo = function () {
'use strict';
console.log(this, typeof this);
}.bind(/regex/);
var fred = function () {
'use strict';
console.log(this, typeof this);
}.bind(function () {});
foo();
bar();
baz();
qux();
quux();
corge();
grault();
garply();
waldo();
fred();
Function.prototype.call()
Array.prototype.foo = function () {
'use strict';
console.log(this, typeof this);
};
['foo'].foo();
Array.prototype.foo.call('bar');
Array.prototype.foo.call(42);
Array.prototype.foo.call(true);
Array.prototype.foo.call(NaN);
Array.prototype.foo.call(undefined);
Array.prototype.foo.call(null);
Array.prototype.foo.call({});
Array.prototype.foo.call(/regex/);
Array.prototype.foo.call(function () {});