1. 程式人生 > >node核心模組--Util

node核心模組--Util

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);