gpt4 book ai didi

javascript - 使用 Douglas Crockford 的函数继承在 Javascript 中调用基方法

转载 作者:数据小太阳 更新时间:2023-10-29 04:41:25 24 4
gpt4 key购买 nike

基本上我如何使用下面的这种模式调用基本方法?

var GS = {};
GS.baseClass = function (somedata) {
var that = {};
that.data = somedata;

//Base class method
that.someMethod = function(somedata) {
alert(somedata);
};

return that;
};

GS.derivedClass = function(somedata) {
var that = GS.baseClass(somedata);

//Overwriting base method
that.someMethod = function(somedata) {
//How do I call base method from here?

//do something else
};
return that;
};

谢谢。

最佳答案

var GS = {};GS.baseClass = function (somedata) {  var that = {};  that.data = somedata;  //Base class method  that.someMethod = function(somedata) {    alert(somedata);  };  return that;};GS.derivedClass = function(somedata) { var that = GS.baseClass(somedata); //Overwriting base method var basemethod = that.someMethod; that.someMethod = function(somedata) {   //How do I call base method from here?    basemethod.apply(that, [somedata]);   //do something else }; return that;};

干杯。

关于javascript - 使用 Douglas Crockford 的函数继承在 Javascript 中调用基方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1467710/

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