-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#20 breaks subclassing jQuery #36
Comments
Seems like the main reason jQuery can be subclassed "idiomatically" (i.e. the reason Coffeescript and ES6 classes don't break here) is because they allow constructors to return objects: http://jsbin.com/qinare/edit?html,console,output However, they're not "well-behaved" subclasses, since if you try to instantiate them you get a jQuery object that isn't an instance of the subclass. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unclear whether this is worth "fixing" (whatever that means), but I think it's worth at least discussing even if we decide just to document a workaround.
If you subclass jQuery with Pjs, many methods that aren't supposed to mutate
this
, like.appendTo()
, will add elements tothis
: http://jsbin.com/faxifed/edit?html,console,outputThis was causing exponentially growing jQuery sets in MathQuill (mathquill/mathquill#629).
This is because jQuery internally calls
this.constructor()
which normally creates a whole new jQuery object, but for Pjs subclasses starting with #20 on v5.0.0 just returnsthis
: https://github.com/jquery/jquery/blob/305f193aa57014dc7d8fa0739a3fefd47166cd44/src/core.js#L72-L84Thanks @jwmerrill!
The text was updated successfully, but these errors were encountered: