fixed constructor property on Spinner instances #61

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@mackuba
mackuba commented Mar 21, 2012

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 added a commit that closed this pull request Mar 21, 2012
@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 Mar 21, 2012
@mackuba
mackuba commented Mar 21, 2012

Ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment