大佬教程收集整理的这篇文章主要介绍了Node.JS中的继承,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
//request.js function request() { this.target = 'old'; console.log('request Target: ' + this.target); } request.prototype.target = undefined; request.prototype.process = function(callBACk) { if (this.target === 'new') return true; return false; } module.exports = request; //create.js function Create() { Create.super_.call(this); this.target = 'new'; } util.inherits(Create,request); Create.prototype.process = function(callBACk) { if (Create.super_.prototype.process.call(this,callBACk)) { return callBACk({ message: "Target is 'new'" }); } else { return callBACk({ message: "Target is not 'new'" }); } } module.exports = Create; //main.js var create = new (require('./create'))(); create.process(function(msg) { console.log(msg); });
我的情况是:
我有request作为基类和Create作为子类. request具有在request构造函数中初始化old的字段目标.
现在,我创建Create类对象,首先调用request构造函数然后用new初始化目标字段.当我调用Create的进程函数时,我希望得到目标的消息是’new’但它返回另一个!
我为此寻找了类似的线程,但所有这些都是我尝试过的!任何人都可以解释什么是错的吗?
提前致谢 :)
以上是大佬教程为你收集整理的Node.JS中的继承全部内容,希望文章能够帮你解决Node.JS中的继承所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。