Draconar
Draconar

Reputation: 1195

Javascript: Having a 'var' keyword before the 'this' keyword

Philosophically, why can't I declare a new variable in JS by using this sort of code:

var this.blah = "hello"

I see that it hangs upon 'this' being a variable that has a meaning already, but -exactly- how?

what about corner cases and constructor functions?

Upvotes: 0

Views: 62

Answers (1)

Trevor Dixon
Trevor Dixon

Reputation: 24332

When you assign properties of an object, you never need the var keyword. That is, you should never have something like var obj.prop = ....

Upvotes: 2

Related Questions