-
Notifications
You must be signed in to change notification settings - Fork 2k
class defined without constructor does not pass instanceof check? #3722
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
Comments
See #2359 and everything that happened around that... |
Thank you for pointing me to the explanation. I do think the schenario @epidemian details at the end is the correct behavior, though. I wish Coffeescript took it up. class Something
constructor: ->
return new SomethingElse()
class SubSomething extends Something
# implied constructor: -> super ^ If this had been written in Javascript, SubSomething.prototype would be I think it would be correct to expect those results: (new Something) instanceof Something # => false
(new Something) instanceof SomethingElse # => true (as "expected", because Something has an other typed constructor)
(new SubSomething) instanceof SubSomething # => true
(new SubSomething) instanceof SomethingElse # => false (it didn't inherit the constructor of Something, even if we didn't override it!) I'm going to go cry in the shower now. what a reality we live in :'[ |
Yeah, i confess i also feel a bit bad every time this issue is revived. It's been long since i was bitten by this behaviour though – i think i've learned not to rely that much on prototypal inheritance 😅
But |
@epidemian: I just think if you're using an external constructor to return an other-typed object from the constructor of another class ( |
@pogs, sorry, i wasn't clear. All i was trying to say is that if you want to have this behaviour... (new Something) instanceof Something # => false
(new Something) instanceof SomethingElse # => true (as "expected", because Something has an other typed constructor)
(new SubSomething) instanceof SubSomething # => true
(new SubSomething) instanceof SomethingElse # => false (it didn't inherit the constructor of Something, even if we didn't override it!) ... the prototype of SubSomething should not be |
I have this code:
I'm trying to understand why
Array2
's constructed from this class definition do not pass theinstanceof
check inArray2.is_equal()
.I've been staring at this for a while so I'm not sure if I'm just missing something obvious. I thought if you did not define a constructor it would be implicitly generated? When I uncomment that line the only change is
Array2.prototype.constructor
is defined, but it looks identical to theArray2
function.Is this by design? What am I doing wrong?
PS: It works on codepen.io when I uncomment that line, but it does not work locally when I run it through my copy of CF 1.8. This makes me doubly confused :( I'm thinking codepen uses 1.7, which means something must have changed?
The text was updated successfully, but these errors were encountered: