Skip to content

Commit

Permalink
refactor: replace delete with hasOwnProperty etc
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jul 3, 2020
1 parent 2cc8171 commit 68a104f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/internal/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ export class Subscription implements SubscriptionLike {
}

if (isFunction(_unsubscribe)) {
// It's not possible to null the _unsubscribe member as there are many
// classes that are derived from Subscriber (which derives from
// Subscription) that implement an _unsubscribe method as a mechanism for
// obtaining unsubscription notifications and some of those subscribers
// are recycled. Deleting the member will release the reference to any
// teardown functions passed in the constructor and will leave any
// methods intact.
delete (this as any)._unsubscribe;
// It's only possible to null _unsubscribe - to release the reference to
// any teardown function passed in the constructor - if it is actually an
// instance property, as there are some classes that are derived from
// Subscriber (which derives from Subscription) that implement an
// _unsubscribe method as a mechanism for obtaining unsubscription
// notifications and some of those subscribers are recycled.
if (this.hasOwnProperty('_unsubscribe')) {
(this as any)._unsubscribe = undefined;
}
try {
_unsubscribe.call(this);
} catch (e) {
Expand Down

0 comments on commit 68a104f

Please sign in to comment.