Skip to main content

Bug Tracker

Side navigation

#13677 closed bug (plugin)

Opened March 27, 2013 12:11PM UTC

Closed March 27, 2013 02:29PM UTC

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:

A library I wrote ( 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.

Attachments (0)
Change History (5)

Changed March 27, 2013 12:43PM UTC by rwaldron comment:1

owner: → rwaldron
status: newassigned

I'll look into this

Changed March 27, 2013 12:48PM UTC by anonymous comment:2

I've sent a pull request addressing the issue:

Changed March 27, 2013 01:56PM UTC by rwaldron comment:3

owner: rwaldrongibson042

Changed March 27, 2013 02:18PM UTC by comment:4

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.

Changed March 27, 2013 02:29PM UTC by gibson042 comment:5

resolution: → plugin
status: assignedclosed