Skip to content

Conversation

audiolion
Copy link
Contributor

The arrow function syntax on a class property will create a new function bound to every instance of the App class that is made. So if you had 1000 App components rendered to the screen we would have 1000 copies of the same function each bound to their own instance.

The .bind(this) in the constructor takes a class method and binds it to the prototype, this means the 1000 apps each get the same reference to the single function that was created on the object prototype.

In this PR I change filterTips to a non-arrow function because it doesn't make sense to bind a class property arrow function. I haven't seen the videos, but if you wanted to demonstrate arrow functions then an alternate version of this PR would be to remove the .bind(this) call from the constructor for filterTips and leave it as an arrow function.

The arrow function syntax on a class property will create a new function bound to every instance of the App class that is made. So if you had 1000 App components rendered to the screen we would have 1000 copies of the same function each bound to their own instance. The `.bind(this)` in the constructor takes a class method and binds it to the prototype, this means the 1000 apps each get the same reference to the single function that was created on the object prototype. In this PR I change filterTips to a non-arrow function because it doesn't make sense to bind a class property arrow function. I haven't seen the videos, but if you wanted to demonstrate arrow functions then an alternate version of this PR would be to remove the `.bind(this)` call from the constructor for `filterTips` and leave it as an arrow function.
@bbelderbos
Copy link
Collaborator

Thanks a lot @audiolion for pointing this out and PR'ing the fix.

@bbelderbos bbelderbos merged commit f048f46 into talkpython:master May 6, 2019
@mikeckennedy
Copy link
Member

Thanks for merging this @bbelderbos and the report @audiolion

@audiolion audiolion deleted the patch-1 branch May 8, 2019 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants