Comment

Comment by sarenji

A small nit:

Specifically the sayName function was created in the global scope, so when it came across the statement this.name it looks in the global scope for the value of name.

It doesn't matter where a function is created, but it matters how it's called. A pretty simple example is that typing sayHello() by itself desugars to sayHello.call(window);, where window is the global scope[1]. JavaScript function invocation is fairly confusing until you learn the rules.

I also really liked Yehuda's JS prototypes article[2]. It really helped me understand them.

[1]: Except in JS strict mode apparently? I don't know too much about that. See http://yehudakatz.com/2011/08/11/understanding-javascript-fu...

[2]: http://yehudakatz.com/2011/08/12/understanding-prototypes-in...

parent sarenji 14 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton