App.CurtainView = Ember.View.extend
name: "CurtainView"
getName: ->
console.log @get("name")
App.ButtonView = App.CurtainView.extend
name: "ButtonView"
getName: ->
# Do something
@_super()
Returns on console:
ButtonView
...but I expect:
CurtainView
I guess this is a context issue - how can I make _super() using the parent objects context?
I don't completely get your goal. This behavior is the same as you would expect with Ruby language, but indeed differs from what you would obtain with Java (assuming you would redefine the name attribute in Button subclass)...
In fact, you have to be aware of the way the Ember's object model is implemented to better understand the behavior you get:
App = Ember.Application.create();
App.CurtainView = Ember.View.extend({
name: "CurtainView",
getName: function() {
console.log(this.get("name"));
}
});
App.ButtonView = App.CurtainView.extend({
name: "ButtonView",
getName: function() {
this._super();
}
});
var c = App.CurtainView.create(),
b = App.ButtonView.create();
console.log(c.getName.toString());
console.log(b.getName.toString());
c.getName();
b.getName();
b.getName.apply(c);
The _super call applies by default to the object on which the current function has been called.
You could override this default behavior by calling getName through apply or call, and passing the appropriated target. But it seems pretty weird to me...
JSFiddle here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With