| Page 1 of 1 | [ 2 posts ] |
|
I have a widget I've already written (called Picker), that extends Widget.
Y.extend(Picker, Y.Widget, { ... } what I'd like is create another widget, DonorPicker, that extends Picker and has all the same attributes and functionality as Picker; I just want to add an additional attribute and additional function call. What is the best way to do this? So say Picker has defined doSomething : function () {}, doSomething2 : function () {} From DonorPicker, I'd like to have doSomething already defined, and just be able to override doSomething2 to do something slightly different. looked at the docs and found a few different examples and I'm confused, any help appreciated. thanks!! |
Juan Ignacio DopazoYUI Contributor
|
Hey! As is true of many things in JavaScript, there are many ways of doing it. The simplest case would be to continue using inheritance. Just create a new "class" that extends your Picker class:
Code: function DonorPicker() { DonorPicker.superclass.constructor.apply(this, arguments); } Y.extend(DonorPicker, Picker, { doSomething2: function () { // overwrite the Picker functionality or... call the superclass! DonorPicker.superclass.doSomething2.apply(this, arguments); } }); Another way would be to use Extensions to keep your inheritance chain short but still reuse code. |
| Page 1 of 1 | [ 2 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