相关疑难解决方法(0)

javascript继承

我知道有很多类似的问题都有很多很好的答案.我试着看一下经典的继承方法,或者那些闭包方法等.不知怎的,我认为它们或多或少是"黑客"方法,因为它并不是javascript的设计目的.(如果我错了,欢迎任何人纠正我).好吧,只要它有效,我满足于经典的继承模式,如:

PARENTClass = function (basevar) { do something here; };
PARENTClass.prototype = { a: b, c: d}; // prototype is auto gen 

// Inheritance goes here
CHILDClass = function (childvar) { do something; };
CHILDClass.prototype = new PARENTClass(*1); // Actual inheritance to the prototype statement
// Instance
CHILDInstance = new CHILDClass(whatever);
Run Code Online (Sandbox Code Playgroud)

上面是某种方式,我理解JS的继承.但是我不知道如何实现的一个场景是,如果我想做一些初始化DURING对象创建(即在构造函数中),并且可以立即使用新对象....我对问题的说明可能不会太清楚了,所以让我用下面的C#Psuedo来解释我想做的事情:

class PARENT {
    public PARENT (basevar) { ... }
}
class CHILD : PARENT {
    public CHILD (basevar) : PARENT (basevar) // constructor of child, and call parent …
Run Code Online (Sandbox Code Playgroud)

javascript inheritance

8
推荐指数
2
解决办法
6547
查看次数

标签 统计

inheritance ×1

javascript ×1