第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

請(qǐng)問express這段源碼大致是什么意思,app上面的handle方法,init方法哪里來的呀

請(qǐng)問express這段源碼大致是什么意思,app上面的handle方法,init方法哪里來的呀

九州編程 2019-04-21 20:14:40
'usestrict';varEventEmitter=require('events').EventEmitter;varmixin=require('merge-descriptors');varproto=require('./application');varRoute=require('./router/route');varRouter=require('./router');varreq=require('./request');varres=require('./response');/***Expose`createApplication()`.*/exports=module.exports=createApplication;/***Createanexpressapplication.**@return{Function}*@apipublic*/functioncreateApplication(){varapp=function(req,res,next){app.handle(req,res,next);};mixin(app,EventEmitter.prototype,false);mixin(app,proto,false);app.request={__proto__:req,app:app};app.response={__proto__:res,app:app};app.init();returnapp;}/***Exposetheprototypes.*/exports.application=proto;exports.request=req;exports.response=res;/***Exposeconstructors.*/exports.Route=Route;exports.Router=Router;/***Exposemiddleware*/exports.query=require('./middleware/query');exports.static=require('serve-static');/***Replaceremovedmiddlewarewithanappropriateerrormessage.*/['json','urlencoded','bodyParser','compress','cookieSession','session','logger','cookieParser','favicon','responseTime','errorHandler','timeout','methodOverride','vhost','csrf','directory','limit','multipart','staticCache',].forEach(function(name){Object.defineProperty(exports,name,{get:function(){thrownewError('Mostmiddleware(like'+name+')isnolongerbundledwithExpressandmustbeinstalledseparately.Pleaseseehttps://github.com/senchalabs/connect#middleware.');},configurable:true});});
查看完整描述

2 回答

?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

mixin就是繼承的意思,類似jquery的extend或者es6的assign,createApplication首先是創(chuàng)建一個(gè)app對(duì)象(js里function也是對(duì)象),然后繼承了EventEimtter(只要是繼承一些on,off,trigger的與事件系統(tǒng)相關(guān)的方法),然后繼承了proto(那些init和handle方法應(yīng)該就是這里來的),最后又app.request繼承了req,app.respond繼承了res(__proto__是對(duì)象的原型鏈,具體可以參考js原型繼承方面的資料),執(zhí)行一下app.init進(jìn)行初始化,并吧app對(duì)象return給你
                            
查看完整回答
反對(duì) 回復(fù) 2019-04-21
?
慕容708150

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊

注意看代碼里的:
mixin(app,proto,false);
意思是說把proto里的所有屬性和方法傳給app,換句話說,proto有的東西,現(xiàn)在app里也有了。然后注意:
varproto=require('./application');
其實(shí)application文件里就有init方法和handle方法。
                            
查看完整回答
反對(duì) 回復(fù) 2019-04-21
  • 2 回答
  • 0 關(guān)注
  • 390 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)