怎么在Nodejs中調用模塊?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
創(chuàng)新互聯(lián)專注于陽明企業(yè)網(wǎng)站建設,成都響應式網(wǎng)站建設公司,商城網(wǎng)站開發(fā)。陽明網(wǎng)站建設公司,為陽明等地區(qū)提供建站服務。全流程定制制作,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務
User.js
//構造方法 function User(id, name, age) { this.id = id; this.name = name; this.age = age; this.enter = function () { console.log(this.name + "進入國家圖書館"); } } /* function User() { this.id; this.name; this.age; this.enter = function() { console.log(this.name + "進入圖書館"); } } */ module.exports = User;
Teacher.js
var User = require('./User'); function Teacher(id, name, age) { User.apply(this, [id, name, age]);//類的繼承 this.teach = function(res) { res.write(this.name + "講課"); } } module.exports = Teacher;
modalcall_1.js
//----------------------n3_modalcall.js模塊的調用------------- var http = require('http'); var User = require('./model/User'); http.createServer(function (request, response) { response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); if (request.url !== "/favicon.ico") { //清除第2此訪問 user = new User(1, "jack", 20); //user.id = 1; //user.name = "張三"; //user.age = 20; user.enter(); response.end(''); } }).listen(8000); console.log('Server running at http://127.0.0.1:8000/');
modalcall_2.js
//----------------------n3_modalcall.js------------- var http = require('http'); var Teacher = require('./model/Teacher'); http.createServer(function(request, response) { response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); if(request.url !== "/favicon.ico") { //清除第2此訪問 teacher = new Teacher(1, "JackLi", 20); teacher.enter(); teacher.teach(response); response.end(''); } }).listen(8000); console.log('Server running at http://127.0.0.1:8000/');
關于怎么在Nodejs中調用模塊問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關知識。
當前名稱:怎么在Nodejs中調用模塊
網(wǎng)頁網(wǎng)址:http://www.chinadenli.net/article36/ipppsg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站設計公司、移動網(wǎng)站建設、標簽優(yōu)化、云服務器、面包屑導航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)