【发布时间】:2018-07-11 03:22:08
【问题描述】:
如何在子原型中访问父原型变量“id”。
const util = require('util');
const Parent = function () {};
Parent.prototype.access = function() {
var id = 1;
};
const Child = function () {};
util.inherits(Child, Parent);
child.prototype.access = function() {
//access Parent.prototype.access variable 'id' here
}
有什么想法吗??
【问题讨论】:
-
你不能。
id只存在于父函数的范围内。在实例上设置它。
标签: javascript node.js oop prototypal-inheritance