1

Topic: foo=func vs window [' bar '] =func

Who explains in what a difference between two these functions? function foo () {console.log (' foo 1: ', foo === window [' foo ']); foo = function () {console.log (' foo 2: ', foo === window [' foo ']); console.trace ();}} function bar () {console.log (' bar 1: ', bar === window [' bar ']); window [' bar '] = function () {console.log (' bar 2: ', bar === window [' bar ']); console.trace ();}} At the first start: foo () console.log> foo 1: true bar () console.log> bar 1: true At the repeated: foo () console.log> foo 2: true console.trace> foo bar () console.log> bar 2: true console.trace> window.bar Why so () if both global and both are added by properties to window?

2

Re: foo=func vs window [' bar '] =func

Hello, rFLY, you wrote: FLY> Why so () if both global and both are added by properties to window? So the first function is not added. It is simply declared variable and windows it has no relation.

3

Re: foo=func vs window [' bar '] =func

Hello, rFLY, you wrote: FLY> Why so () if both global and both are added by properties to window? window [' x '] = it is a call of property of object window. At normal function declaration this property is not caused directly. That is, binding works on a miscellaneous.

4

Re: foo=func vs window [' bar '] =func

Hello, rFLY, you wrote: FLY> FLY> function foo () {FLY> foo = function () {} FLY>} FLY> function bar () {FLY> window [' bar '] = function () {} FLY>} FLY> In both cases at function declaration the link is located on it in property window. But in the first case variable value foo is re-recorded, but  on foo remains in property window. As a result it is possible to cause both foo () and window [' foo '] (). In the second case in property window the link to new function is located. What then happens to earlier declared variable bar? Original bar it is possible to cause or it is deleted a garbage collector or what happens to it?

5

Re: foo=func vs window [' bar '] =func

Hello, rFLY, you wrote: FLY> In both cases at function declaration the link is located on it in property window. With Which method is located? FLY> but in the first case variable value foo is re-recorded, but  on foo remains in property window. As a result it is possible to cause both foo () and window [' foo '] (). FLY> In the second case in property window the link to new function is located. What then happens to earlier declared variable bar? Original bar it is possible to cause or it is deleted a garbage collector or what happens to it? In both cases you re-record the link. In both cases the original version is removed by garbage collection. The difference only in, whether is caused a setter explicitly or binding becomes in another way.

6

Re: foo=func vs window [' bar '] =func

Hello, Ikemefula, you wrote: I> with Which method is located? Judging by it right after function declarations (that is even before copying) console.log (' foo 1: ', foo === window [' foo ']) I> In both cases you re-record the link. In both cases the original version is removed by garbage collection. The difference only in, whether is caused a setter explicitly or binding becomes in another way. So in that that and a question. If in both cases , I will make a reservation - by sight, one is made and too why a difference and in the second case the call happens through property window. And how it can be applied? Well that is in what cases the first method, and in what second is preferable. Or on the contrary in what there can be a problem at usage of one and the second.

7

Re: foo=func vs window [' bar '] =func

Hello, rFLY, you wrote: FLY> Who explains in what a difference between two these functions? Formally a difference that window is not obliged to be global object, though in browsers it always so.

8

Re: foo=func vs window [' bar '] =func

Hello, rFLY, you wrote: FLY> Hello, Ikemefula, you wrote: I>> with Which method is located? FLY> judging by it right after function declarations (that is even before copying) FLY> FLY>console.log (' foo 1: ', foo === window [' foo ']) FLY> It is the answer to a question "when". Is located by means of direct recording in object window. Window it is object DOM, to JavaScript VM it has no relation, these are different and independent entities, which only  the friend with another. I>> in both cases you re-record the link. In both cases the original version is removed by garbage collection. The difference only in, whether is caused a setter explicitly or binding becomes in another way. FLY> so in that that and a question. If in both cases , I will make a reservation - by sight, one is made and too why a difference and in the second case the call happens through property window. And how it can be applied? Well that is in what cases the first method, and in what second is preferable. Or on the contrary in what there can be a problem at usage of one and the second. I told: window [' bar '] = Here it is explicit  in object window. This line does all magic.