#30896 closed defect (bug) (fixed)
Backbone Views should use `listenTo` when listening to models
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | |
Focuses: | javascript | Cc: |
Description
I just read 2 books about Backbone. Chapter 1 of both says to never do this inside of a view:
this.model.on( 'whatever', this.boom, this )
You should do:
this.listenTo( this.model, 'whatever', this.boom )
Why you ask? The listeners won't be properly removed when the view is destroyed (creating Ghost Views), causing problems with JS garbage collection because the view is still shackled to the model. Using listenTo
solves that problem.
Change History (4)
Note: See
TracTickets for help on using
tickets.
In 31045: