Why are the properties undefined?

I have some problems with enyo properties. And I write test code like this:
enyo.kind({
	name: "Ok.Panorama.Block",
	drag_at1: 0,
	published: {
               drag_at: 0
        }
});
I output the object using console.log. I found that the drag_at1 and drag_at are both undefined. I must call set or this.drag_at1 = 0 to initialize it.

Why are the properties undefined?

What's the profits to use getter/setter instead of direct this.drag_at1 = 0? I like IDE auto hint context. If I use direct properties access, I can use IDE auto hint context.

Comments

  • What you're getting back is a constructor, and not an instance of your kind. You can create an instance of your kind as such:
    
    enyo.kind({
    	name: "MyKind",
    	drag_at1: 0,
    	published: {
                   drag_at: 0
            }
    });
    var myKind = new MyKind();
    console.log(myKind.drag_at1);
    console.log(myKind.drag_at);
    
    Your properties should appear on the prototype of the constructor, but due to how deferral works in Enyo (before 2.6), those properties won't show up until you create an instance of your kind. You can use direct property setting and retrieval on the instance, but keep in mind that doing so will not trigger such things as automatic change handlers when setting the value of a property.
Sign In or Register to comment.