這篇文章主要介紹了Nodejs模塊如何調(diào)用,具有一定借鑒價(jià)值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)大廠,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220
User.js
//構(gòu)造方法 function User(id, name, age) { this.id = id; this.name = name; this.age = age; this.enter = function () { console.log(this.name + "進(jìn)入國家圖書館"); } } /* function User() { this.id; this.name; this.age; this.enter = function() { console.log(this.name + "進(jìn)入圖書館"); } } 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模塊的調(diào)用------------- 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/');
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享Nodejs模塊如何調(diào)用內(nèi)容對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,遇到問題就找創(chuàng)新互聯(lián),詳細(xì)的解決方法等著你來學(xué)習(xí)!