Reputation: 76
So what is the difference between the following 2 examples?
var SomeFn = function (name){this.constructor.SomeVarible = name}
And
var SomeFn = function (name){this.SomeVarible = name}
Upvotes: 1
Views: 134
Reputation: 816452
Assuming you have
var obj = new SomeFn('foo');
In the first case, the value will be assigned to SomeFn.SomeVarible
, since this.constructor
refers to SomeFn
. I actually don't see a reason why one would do something like this, but if anyone has an idea, please let me know.
In the second case, it will be assigned to obj.SomeVariable
, since this
refers to the newly created object and is assigned to obj
.
Upvotes: 4