var obj = { arrow: () => console.log(this), fn: function() { console.log(this) }, fnObj: new Function('console.log(this)'), fnObjBind: new Function('console.log(this)').bind(this), fnObjBindNull: new Function('"use strict"; console.log(this)').bind(undefined) }
console.log('global obj.fn()', obj.fn())
console.log('global obj.fnObj()', obj.fnObj())
console.log('global obj.arrow()', obj.arrow())
console.log('global obj.fnObjBind()', obj.fnObjBind())
function AAA() { var obj = { arrow: () => console.log(this), fn: function() { console.log(this) }, fnObj: new Function('console.log(this)'), fnObjBind: new Function('console.log(this)').bind(this), fnObjBindNull: new Function('"use strict"; console.log(this)').bind(undefined) } console.log('AAA obj.fn()', obj.fn()) {arrow: ƒ, fn: ƒ, fnObj: ƒ, fnObjBind: ƒ, fnObjBindNull: ƒ} console.log('AAA obj.fnObj()', obj.fnObj()) #document (https: console.log('AAA obj.arrow()', obj.arrow()) #document (https: console.log('AAA obj.fnObjBind()', obj.fnObjBind()) undefined }
const AAAdocument = AAA.bind(document) AAAdocument();
|