ded / klass

a utility for creating expressive classes in JavaScript
751 stars 78 forks source link

Leaking global 'supr' symbol when calling supr using methods without proper this context #30

Open dwt opened 8 years ago

dwt commented 8 years ago

Hi there,

we just noticed that klass will leak a global 'supr' value when you call a supr-using method without a this-context.

What happens, is that the wrapper will assign this.supr to the correct super method - but of course this is now the windows (or global) object.

I'm actually not entirely sure how this should be fixed, what we came up with was to either raise if this === window or just remove this.supr after the super call has taken place if the supr key wasn't not the object before the call.

Interestingly this.supr(...) actually works, even when the wrong this context is used for a method. (Which is actually quite surprising)

Asserting that this cannot be the global object supr() using code seems to make most sense here.

What do you think?