| Page 1 of 1 | [ 3 posts ] |
|
Hello YUI3 experts,
coming from YUI2 I want to create my own classes. They should support all the nice automatic event listeners and fireing of events when attributes are changed etc. 1.) my problem: attributes I defined in MyClass.ATTRS are not available in myClass.constructor (as well as in initializer: function(cfg) ). How can that be Code: YUI.add('my-examples', function(Y) { Y.namespace('MyNamespace'); Y.MyNamespace.MyClass = function(myConstructorArgument) { Y.MyNamespace.MyClass.superclass.constructor.call(this, conf); // apply does not work, must use call this.myAttribute.key = 'value'; // does not work. this.myAttribute = NULL why? }; Y.MyNamespace.MyClass.NAME = "myClass"; Y.MyNamespace.MyClass.ATTRS = { myAttribute: {key:"defaultValue"} }; Y.extend(Y.MyNamespace.MyClass, Y.Base, { initializer: function(cfg) { this.myAttribute.key = 'newValue'; // does not work, too! this.myAttribute = NULL, why? } }; },'*',{requires:['base'], skinnable:false}); 2.) What is the correct way to get an object of such a class Code: var myNewClass = Y.Base.build("myClass", Y.MyNamespace.MyClass,[ ]); var myInstance1 = new myNewClass(myConstructorArgument); // it has no attribs from ATTRS var myNewInstance2 = new Y.MyNamespace.MyClass(myConstructorArgument); // is this in YUI3 class hierarchy allowed? It has as well no attribs from ATTRS The documentation does not give me a consietnt picture, because the examples from Y.Base docu differ from the 'Getting started: extends' examples. Thanks for your help. |
|
Joh --
You are missing the fact that Attributes are accessed via getters/setters. This example works: Attribute ExampleClick here to see the revision history on this Gist. |
|
Concerning my second question: 2.) What is the correct way to get an object of such a class Code: // (1) var myNewClass = Y.Base.build("myClass", Y.MyNamespace.MyClass,[ ]); var myInstance1 = new myNewClass(myConstructorArgument); // (2) var myInstance2 = new Y.MyNamespace.MyClass(myConstructorArgument); // is this in YUI3 class hierarchy allowed? As you used the first way to build a new class and instance, i guess the second (easier) way is not supposed to be used? |
| 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