Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixed constructor property on Spinner instances #61

Closed
wants to merge 1 commit into from

2 participants

@mackuba

When you overwrite Spinner.prototype to define instance methods, it loses the the constructor property which is set by default to the class itself, which can be used to identify object constructors. This may break inheritance chain if the user makes a class that inherits from Spinner, e.g. using Coffeescript's class inheritance.

This is how it should work:

function Spinner() {}
=> undefined
(new Spinner).constructor
=> function Spinner() {}

This is what happens if you overwrite the prototype:

Spinner.prototype = {}
=> Object
(new Spinner).constructor
=> function Object() { [native code] }
@mackuba mackuba fixed constructor property on Spinner instances
when Spinner.prototype is overwritten to define instance methods,
it loses the previously set constructor property which is used
to identify object constructors; this may break inheritance chain
if another class inherits from Spinner
8bf25d8
@fgnass fgnass closed this pull request from a commit
@fgnass Don't overwrite the prototype to preserve the constructor property.
Instead of restoring the property (as suggested in the pull request) this patch uses the existing `merge` function in order to reduce the file size. Fixes #61
ee7b4d5
@fgnass fgnass closed this in ee7b4d5
@mackuba

Ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2012
  1. @mackuba

    fixed constructor property on Spinner instances

    mackuba authored
    when Spinner.prototype is overwritten to define instance methods,
    it loses the previously set constructor property which is used
    to identify object constructors; this may break inheritance chain
    if another class inherits from Spinner
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 0 deletions.
  1. +3 −0  spin.js
View
3  spin.js
@@ -228,6 +228,9 @@
}
};
+ // fix constructor field after overwriting prototype so that (new Spinner).constructor == Spinner
+ Spinner.prototype.constructor = Spinner;
+
/////////////////////////////////////////////////////////////////////////
// VML rendering for IE
/////////////////////////////////////////////////////////////////////////
Something went wrong with that request. Please try again.