Re: [JSMentors] global object property access

2011-02-05 Thread Garrett Smith
On 2/4/11, mcot wrote: > I am currently seeing some weird behavior with the global object: > > console.log(window.foo); // this returns undefined > console.log(this.foo);// this returns undefined As expected, getting a property off an object, the prototype chain is searched. When that ha

Re: [JSMentors] global object property access

2011-02-04 Thread Juriy Zaytsev
On Fri, Feb 4, 2011 at 6:44 PM, mcot wrote: > I am currently seeing some weird behavior with the global object: > > console.log(window.foo); // this returns undefined > console.log(this.foo);// this returns undefined > console.log(foo); // this is a reference error > > The

Re: [JSMentors] global object property access

2011-02-04 Thread Jason Persampieri
On Fri, Feb 4, 2011 at 4:07 PM, Michael Geary wrote: > The first two cases are identical to each other, because window === this > when your code runs in the global scope. And as you noted, it is not an > error to attempt to dereference a nonexistent property of an object - you > simply get the un

Re: [JSMentors] global object property access

2011-02-04 Thread Michael Geary
There's nothing weird going on there, it's all defined and expected behavior. The first two cases are identical to each other, because window === this when your code runs in the global scope. And as you noted, it is not an error to attempt to dereference a nonexistent property of an object - you s