Why does the first warning show 3 and the second warning show 1? I understand that thischanges the scope, but does not go(), and foo.baz.bar()is the same thing?
this
go()
foo.baz.bar()
var x = 3; var foo = { x: 2, baz: { x: 1, bar: function() { return this.x; } } } var go = foo.baz.bar; alert(go()); alert(foo.baz.bar());
The execution context of the first warning is a Window object. The execution context of the second warning is a function called bar. It. The execution context is a bit to understand.
Here are the details: https://tc39.imtqy.com/ecma262/#sec-execution-contexts
JavaScript this . , , , , foo.baz.bar. go
foo.baz.bar
go
function() { return this.x; }
, foo. window global ( dev).
foo
window
global
Source: https://habr.com/ru/post/1695784/More articles:Why two different normalized results from Python vs R - pythonDelete duplicates, keeping the most frequent row - rConverting a command line argument to char - cC ++ The difference between initializing a copy and initializing a constant reference if the value is obtained from a member variable - c ++What is a safe and standard way to test forms with reCaptcha? - unit-testingUnfortunately, error from Instagram API: this endpoint has been deleted - instagram-apiAllow variable name specified only for stack frame object - pythonWhat is `null vK` in Perl? - perlHow to enable backticks in active mysql codeigniter record - databaseOpenrefine: Split multi-valued cells with a token / word? - nlpAll Articles