node核心模块--Util

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41556165/article/details/84638335
class child{}
class parent{
	constructor(){
	}
	sleep(){console.log("i'm sleeping")}
}
parent.prototype.sleep = "sleeping!";


//原生写法:
	child.prototype.__proto__ = parent.prototype;
	child.prototype = Object.create(parent.prototype);
	Object.setPrototype(child.prototype,parent.prototype);
//实现继承(只继承公有)先继承再new
let child = new child();
let parent = new parent();
//使用util模块:
	let util = require('util');
	util.inherits(child,parent);

猜你喜欢

转载自blog.csdn.net/weixin_41556165/article/details/84638335