gpt4 book ai didi

javascript - super Backbone

转载 作者:IT王子 更新时间:2023-10-29 02:49:30 24 4
gpt4 key购买 nike

当我覆盖 Backbone.Modelclone() 方法时,有没有办法从我的植入中调用这个覆盖的方法?像这样:

var MyModel = Backbone.Model.extend({
clone: function(){
super.clone();//calling the original clone method
}
})

最佳答案

你会想要使用:

Backbone.Model.prototype.clone.call(this);

这将使用 this(当前模型)的上下文从 Backbone.Model 调用原始的 clone() 方法。

来自 Backbone docs :

Brief aside on super: JavaScript does not provide a simple way to call super — the function of the same name defined higher on the prototype chain. If you override a core function like set, or save, and you want to invoke the parent object's implementation, you'll have to explicitly call it.

var Note = Backbone.Model.extend({
set: function(attributes, options) {
Backbone.Model.prototype.set.apply(this, arguments);
...
}
});

关于javascript - super Backbone ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8596861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com