What's the difference between a 'var' declared variable and 'this' created property in Javascript?

javascript

Solution

If those functions are used as functions, the this keyword will make the variable static. If the function is called twice, this.something will still have its value while the first subject will erase the variable data once the function has finished executing.

If you are using them as class constructors, var will define a private variable and this will declare a public variable.

See this fiddle: http://jsfiddle.net/UUFuX/1/

Problem

first using var ``` function testCode(some) { var something = some; } ``` the second using this ``` function testCode2(some) { this.something = some ; } ```

Original source