Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for JavaScript prototype and call()

Current License: CC BY-SA 3.0

9 events
when toggle format what by license comment
Apr 20, 2014 at 23:34 history edited user3299259 CC BY-SA 3.0
added 130 characters in body
Apr 20, 2014 at 23:31 comment added jfriend00 Geez, then you SHOULD explain that in your answer. Your answer is pretty meaningless to most without an explanation.
Apr 20, 2014 at 23:30 comment added user3299259 again this was an example what can happen if you do not call the superconstructor , this was not an example for how it should be done. a change of the a.color will also effect b.color
Apr 20, 2014 at 23:27 comment added jfriend00 I think the OP's question has been answered. I just don't think we should be "teaching" methods that don't call the base constructor because those are not general purpose solutions that will always work.
Apr 20, 2014 at 23:26 comment added user3299259 i dont know where this discussion goes to now, because we wrote comments above and now here. do you want to talk about the problems which can happen here, or do you want to talk about the second way i edited in my first answer see please write comments above
Apr 20, 2014 at 23:22 comment added jfriend00 OK, imagine the SuperType constructor requires an argument. How does this design pattern work then?
Apr 20, 2014 at 23:20 comment added user3299259 thats for Blake (its about how problems can build up) because he wrote thanks for your detailed answer! but what does it mean by "the statement this.color=["blue","yellow"] is not executed?"if I do var instance1= new SubType(); and do console.log(instance1.color), I can still see the color is not null – Blake 2 hours ago and what is the difference if constructor is called or not? – Blake 2 hours ago this is not a way to do it, it shows how it should not be done... the second way i edited in my first post
Apr 20, 2014 at 22:46 comment added jfriend00 So you're trying to train the OP NOT to call the base class constructor. Sure, it doesn't make a difference in this case, but I know of no site that teaches this as a good design pattern or the preferred practice.
Apr 20, 2014 at 20:35 history answered user3299259 CC BY-SA 3.0

AltStyle によって変換されたページ (->オリジナル) /