Created
September 3, 2013 14:45
-
-
Save pjetr/6424911 to your computer and use it in GitHub Desktop.
enyo extending as suggested in the enyojs channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enyo.kind({ | |
name: "pjetr.Object", | |
kind: enyo.Object, | |
bubble: function(inEventName, inEvent, inSender){ | |
console.log(arguments); | |
}, | |
create: function(){ | |
this.inherited(arguments); | |
enyo.mixin(this, new enyo.Component); | |
}, | |
}); | |
var obj = new pjetr.Object(); |
enyo.kind({
name: "pjetr.Object",
kind: enyo.Object,
bubbleUp: function(inEventName, inEvent, inSender){
console.log(arguments);
this.inherited(arguments);
},
constructor: function(){
enyo.mixin(this, new enyo.Component);
this.inherited(arguments);
},
});
var obj = new pjetr.Object();
this works, but it seems to overwrite the function bubbleUp.
There must be another parameter set to true
in mixin()
to not overwritte existing methods.
The way I am proposing is more JavaScript specific than framework specific. In order to call function from super class you need to capture it on you closure before you overwritte it. In the closure of bubbleUp now is the super class call instead of the one that is exposed from the object. Notice the this.bubbleUp.apply(this, arguments);
refers to the superclass
enyo.kind({
name: "pjetr.Object",
kind: enyo.Object,
bubbleUp: function(inEventName, inEvent, inSender){
console.log(arguments);
this.bubbleUp.apply(this, arguments);
},
constructor: function(){
enyo.mixin(this, new enyo.Component, true);
this.inherited(arguments);
},
});
var obj = new pjetr.Object();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
enyo.kind({
name: "pjetr.Object",
kind: enyo.Object,
bubble: function(inEventName, inEvent, inSender){
console.log(arguments);
},
constructor: function(){
enyo.mixin(this, new enyo.Component);
this.inherited(arguments);
},
});
var obj = new pjetr.Object();