Bug Tracker

Opened 7 years ago

Closed 7 years ago

#13677 closed bug (plugin)

jQuery objects assume their constructor is always jQuery, which breaks prototypical inheritance from jQuery

Reported by: nathan@… 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 7 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: newassigned

I'll look into this

comment:2 Changed 7 years ago by anonymous

I've sent a pull request addressing the issue:

https://github.com/jquery/jquery/pull/1213

comment:3 Changed 7 years ago by Rick Waldron

Owner: changed from Rick Waldron to gibson042

comment:4 Changed 7 years ago by nathan@…

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 7 years ago by gibson042

Resolution: plugin
Status: assignedclosed
Note: See TracTickets for help on using tickets.