Opened 10 years ago
Closed 10 years ago
#13677 closed bug (plugin)
jQuery objects assume their constructor is always jQuery, which breaks prototypical inheritance from jQuery
Reported by: | Owned by: | gibson042 | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
A library I wrote (http://github.com/nathansobo/space-pen) for a large internal project at GitHub allows you to build view objects that inherit from jQuery with prototypical inheritance. Unfortunately, there's 3 places in jQuery core where code references this.constructor
when it could just reference the jQuery
constructor directly to build new element sets.
I am able to build instances of my inheriting constructor correctly, but when I try to call methods on it like find
, jQuery tries to call my constructor when it really wants to call the original jQuery
constructor, which causes problems. The only way around it short of changing jQuery is to assign this.constructor = jQuery
on my objects in their constructor, but this creates surprises when other code wants to inspect the inheriting object's constructor and it sees the wrong value.
The jQuery unit tests still pass when I replace the 3 references to this.constructor
with a reference to the local jQuery
variable in core.
Change History (5)
comment:1 Changed 10 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | new → assigned |
comment:3 Changed 10 years ago by
Owner: | changed from Rick Waldron to gibson042 |
---|
comment:4 Changed 10 years ago by
I've closed the pull request. Now I understand there are good reasons for the way it's currently implemented, and have taken gibson042's suggestion to override the pushStack
and end
methods instead. This ticket can be closed.
comment:5 Changed 10 years ago by
Resolution: | → plugin |
---|---|
Status: | assigned → closed |
I'll look into this