var obj1 = {
x: 3,
f: function() {
return (this.x);
}
};
alert(obj1.f());
var f = obj1.f;
alert(f());var f = function (){
console.log('common:',this.toString());
};
f();
var fStrict = function (){
"use strict";
console.log('strict:', this);
};
fStrict();var Obj = {toString:function(){ return "[object Obj]";}};
Obj.f = function (){
console.log('common:',this.toString());
};
Obj.f();
Obj.fStrict = function (){
"use strict";
console.log('strict:', this.toString());
};
Obj.fStrict();function Foo(name){
this.name = name;
}
var foo = new Foo('foo');
console.log(foo);class A {}
class B extends A {
constructor(){
console.log(this);
}
}
var b = new B();var f = function (){
console.log('common:',this);
};
f.call({o:'object'});
var fStrict = function (){
"use strict";
console.log('strict:', this);
};
fStrict.apply({o:'object'});var specialMap = {'b':'specialB','d':'specialD'}
var source= ['a','b','c','d','e'];
var mapped = source.map(function(el){
return this[el] || ('common-'+el);
},specialMap);
console.log('source:',source);
console.log('mapped:',mapped);function A(){}
var a = function (){};function A(){console.log(typeof this,'is window', this === window);}
console.log('execute with null');
A.bind(null)();
console.log('execute with undefined');
A.bind(undefined)();
function A1(){'use strict'; console.log(typeof this, this);}
console.log('execute with null');
A1.bind(null)();
console.log('execute with undefined');
A1.bind(undefined)();
function A(){console.log(this);}
var B = A.bind({o:'object'});
console.log('execute binded');
B();
console.log('execute with call');
B.call({another: 'some new object'});
console.log('execute as constructor');
new B();
function A(){
this.t = (place)=>console.log(place,this);
}
var a = new A()
a.t('method:');
var tt = a.t;
tt('free function execute:');
tt.call({o:'object'},'using call function');
new tt('constructor');