> Hi guys,
>
> the first test in
>
> http://jsperf.com/prototype-members-vs-instance-members/6
>
> is written like this:
>
> function MyClass1() {
>
>
>   this._privateAttribute = 42;
>
> }
>
>
> MyClass1.prototype = {
>
>
>   _privateMethod: function() {
>
>
>     return this._privateAttribute;
>   },
>
>
>
>   publicMethod: function() {
>
>
>     return this._privateMethod();
>
>
>   }
> };
>
> When I was reading this articles
> http://javascriptweblog.wordpress.com/2010/08/30/understanding-javascripts-this/
> http://seanmonstar.com/post/707068021/4-ways-functions-mess-with-this
> I was thinking, wouldn't the line in the first test case
>
> this._privateAttribute = 42;
>
> produce a global variable?
> Because this in the function context is the window object. Right?
> Please give me a heads up I'm not really sure whats happening here...
> Regards

In case the a new object is created by calling

new MyClass1

Then the context inside MyClass1 would change a newly initialized object.

If you call it with just
MyClass1()

then the `this` will be the global object and it will not recieve any
of the prototype functions.

-- 
Poetro

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to