Skip to content

Event: Restore the constructor property on jQuery.Event prototype #1580

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

Closed
wants to merge 1 commit into from

Conversation

dcherman
Copy link
Contributor

The original definition of the jQuery.Event prototype was paving over the
constructor property which was causing jQuery.isPlainObject to
improperly report that an instance of jQuery.Event was a plain object.

Fixes #15090

@@ -659,7 +659,7 @@ jQuery.Event = function( src, props ) {

// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
jQuery.Event.prototype = {
jQuery.extend( jQuery.Event.prototype, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a "hot path" but to fix the issue described, the following is sufficient:

jQuery.Event.prototype = {
  constructor: jQuery.Event,
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the reason I went with $.extend is that as you pointed out, it's not a hot path and it turned out to be 1 byte smaller after gzip. I'm fine doing it either way if you have a preference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I suggested is the correct way to fix the constructor property problem. While I appreciate that attention was paid to the size of the patch, it's not immediately clear that jQuery.extend is being used to prevent the described problem.

edit

I'd accept the 1 byte cost for correctness.

The original definition of the jQuery.Event prototype was paving over the
`constructor` property which was causing jQuery.isPlainObject to
improperly report that an instance of jQuery.Event was a plain object.
@dcherman dcherman changed the title Event: Extend the jQuery.Event prototype instead of paving over it Event: Restore the constructor property on jQuery.Event prototype May 15, 2014
@dmethvin
Copy link
Member

Sounds like we settled on setting the constructor property...wow you're fast @dcherman!

@dmethvin dmethvin added this to the 1.12/2.2 milestone May 28, 2014
gibson042 pushed a commit that referenced this pull request Sep 4, 2014
The original definition of the jQuery.Event prototype was paving over the
`constructor` property which was causing jQuery.isPlainObject to
improperly report that an instance of jQuery.Event was a plain object.

Fixes #15090
Closes gh-1580

(cherry picked from commit b807aed)
@gibson042 gibson042 closed this in b807aed Sep 4, 2014
mescoda pushed a commit to mescoda/jquery that referenced this pull request Nov 4, 2014
The original definition of the jQuery.Event prototype was paving over the
`constructor` property which was causing jQuery.isPlainObject to
improperly report that an instance of jQuery.Event was a plain object.

Fixes #15090
Closes jquerygh-1580

(cherry picked from commit b807aed)
@dmethvin dmethvin added the Bug label Dec 4, 2014
markelog pushed a commit that referenced this pull request Nov 10, 2015
The original definition of the jQuery.Event prototype was paving over the
`constructor` property which was causing jQuery.isPlainObject to
improperly report that an instance of jQuery.Event was a plain object.

Fixes #15090
Closes gh-1580
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

3 participants