Javascript 如何访问构造函数中的类变量?(node.js OOP)

Javascript 如何访问构造函数中的类变量?(node.js OOP),javascript,oop,node.js,Javascript,Oop,Node.js,是否有某种方法可以访问构造函数中的类变量 var Parent = function() { console.log(Parent.name); }; Parent.name = 'parent'; var Child = function() { Parent.apply(this, arguments); } require('util').inherits(Child, Parent); Child.name = 'child'; i、 e父类的构造函数应该记录“父类”,子类的

是否有某种方法可以访问构造函数中的类变量

var Parent = function() {
  console.log(Parent.name);
};
Parent.name = 'parent';

var Child = function() {
  Parent.apply(this, arguments);
}
require('util').inherits(Child, Parent);
Child.name = 'child';
i、 e父类的构造函数应该记录“父类”,子类的构造函数应该基于每个类中的某个类变量记录“子类”


上面的代码并不像我预期的那样工作。

这里是vanilla js:

var Parent = function() {
  console.log(this.name);
};
Parent.prototype.name = 'parent';

var Child = function() {
  Parent.apply(this, arguments);
}

Child.prototype = new Parent();
Child.prototype.constructor = Child;
Child.prototype.name = 'child';

var parent = new Parent();
var child = new Child();
utils.inherits只是简化了

Child.prototype = new Parent();
Child.prototype.constructor = Child;
进入


utils.inherits做的比描述的更多(没有子类的实例)。
util.inherits(Child, Parent);