Hi,
I have an issue with statics properties on a kind. I declare a static variable in my kind, then I need to set it from outside this kind. The thing is that this doesn't work.
Here's an example:
http://jsfiddle.net/Bm8RX/1/The alert should display "a, b, c" but displays an empty string. Why is the array empty?
Comments
http://jsfiddle.net/Bm8RX/2/
foo
before you've created an instance of MyKind, you're setting it on a different object than you're alerting on in your method. That's why @bbito 's code works; an instance of MyKind was created thus fully initializing the constructor. Check out Oop.js for the internals if you're curious.You can turn this behavior off by adding
noDefer: true
to your kind's definition.http://jsfiddle.net/Bm8RX/4/
Thanks for the help!
statics
and my read of that page seems to indicate that the use of (public)statics
should enforce anoDefer
, and that onlyprotectedStatics
should show the behavior we are seeing.enyojs.com/docs/2.4.0/key-concepts/kinds.html So it seems that public
statics
that are set within the kind's constructor can be read prior to instantiating an instance*, but cannot be manipulated from outside the constructor until an instance is created - is that right?[EDIT]
* publicstatics
can be read AND set prior to instantiating:jsfiddle.net/Bm8RX/6/
-Pardon my confusion!
[EDIT2] * I think I was right the first time...:
jsfiddle.net/Bm8RX/7/
statics
hash gets copied onto the deferred constructor butprotectedStatics
does not. Both are copied again onto the real constructor once it is initialized so if you modify a static member, those changes are lost.statics
is different when the kind is set tonoDefer
. That part of the docs led me to believe that includingstatics
in a kind definition prevented deferral but it seems that is only partially true...