| Page 1 of 1 | [ 3 posts ] |
|
Hi everyone,
Is there a way to get to the parent class' method while inside a subclass method that is overriding the parent method? In the java world, you can call super(), which can invoke the parent classes method first. Is there something similar I can do with the class that is created from YUI's Y.Base.create()? If I can't have a parent reference with Y.Base.create(), then what would be the best way to do this? Thanks. |
|
The subclass constructor function will have a static `superclass` property which points to the superclass's prototype, so you can reference superclass methods from there. Note, you have to invoke them via call/apply.
Code: SubClass.prototype.doMagicStuff = function (toads, batWings, fairyDust) { var potion = SubClass.superclass.doMagicStuff.call(this, toads, batWings); potion.addIngredient(fairyDust); return potion; }; |
|
Hi Luke,
While in debugging mode, I was looking for the static superclass property on the class object and didn't see it. But it makes sense now after reading up on static properties/methods for JS Thanks for the tip on using call/apply. I saw similar syntax elsewhere when the superclass property was used but didn't think much of it at the time. -Daniel |
| Page 1 of 1 | [ 3 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group