The right way to 'call' a class attribute inside the same class

Erik python at
Sat Dec 17 20:01:10 EST 2016

On 16/12/16 01:17, Chris Angelico wrote:
> On Fri, Dec 16, 2016 at 11:36 AM, Erik <python at> wrote:
>> On 12/12/16 23:23, Chris Angelico wrote:
>>> In JavaScript, it's normal to talk about "calling a function as a
>>> constructor". When you do, there is a 'this' object before you start.
>> No there isn't. There is an implicit binding of a variable called "this"
>> based on the syntactic sugar of whether you're calling a function as method
>> on an object or not.
>> In "strict" mode, [blah, blah, blah]

> I'm talking about when you call a function as a constructor: "new
> Foo()". Doesn't that have a 'this' object before the function starts?

Yes, in that case there is (I didn't grok that you meant using 'new' by 
"calling a function as a constructor", but it's obvious now you spell it 

I wish I could find the resource I originally learned this stuff from, 
because it's quite enlightening and I'd like to link to it here - if one 
understands how things work generally under the covers it all makes much 
more sense, but I guess that's also a bad advert for a language (and why 
a lot of people get confused at first, and why it's a bit of a mess ;)).

But yes you're correct, in the case of using "new Func()" then "Func" is 
called with an implicit binding of 'this' that is to a newly created object.


More information about the Python-list mailing list