gpt4 book ai didi

javascript - 在 ES6 中调用重写方法

转载 作者:行者123 更新时间:2023-11-28 07:40:27 25 4
gpt4 key购买 nike

假设我有以下代码:

import Authenticator from 'simple-auth-torii/authenticators/torii';

export default Authenticator.extend({
restore: function(data) {

},
authenticate: function(provider, options) {

},
invalidate: function(data) {

}
});

如何从 authenticate 方法内部调用基类 authenticate 方法?

最佳答案

在常见的 ES5 情况下,不使用 Ember.Object.extend 方法和 this._super,也不使用 ES6 类继承,必须使用标准 callapply方法来实现它。因此,要调用父类的 authenticate 方法,您必须将其添加到子方法中:

Authenticator.prototype.authenticate.call(this /* some args here */);

关于javascript - 在 ES6 中调用重写方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28094169/

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