欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

nodejsjs模塊加載-創(chuàng)新互聯(lián)

本文地址:http://www.cnblogs.com/jasonxuli/p/4381747.htmlnodejsjs模塊加載

nodejs的非核心模塊(core module)加載主要使用的就是module.js。

10余年的松原網站建設經驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。網絡營銷推廣的優(yōu)勢是能夠根據(jù)用戶設備顯示端的尺寸不同,自動調整松原建站的顯示方式,使網站能夠適用不同顯示終端,在瀏覽器中調整網站的寬度,無論在任何一種瀏覽器上瀏覽網站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)從事“松原網站設計”,“松原網站推廣”以來,每個客戶項目都認真落實執(zhí)行。

項目主模塊(index.js/main.js等)加載使用的應該是module.js中的runMain(),其他js模塊加載流程基本上是:

1,獲取js文件信息;

2,new Module();

3,讀取js文件內容,封裝到一個function中,同時注入module本身,module.exports,包裝過的require函數(shù)等變量;

4,在某個上下文環(huán)境中執(zhí)行這個封裝后的function;

5,返回module.exports;

下面是摘出的主要代碼

module.js:

// Loads a module at the given file path. Returns that module's
// `exports` property.Module.prototype.require = function(path) { assert(path,'missing path'); assert(util.isString(path),'path must be a string'); return Module._load(path, this); }; // Check the cache for the requested file. // 1. If a module already exists in the cache: return its exports object. // 2. If the module is native: call `NativeModule.require()` with the // filename and return the result. // 3. Otherwise, create a new module for the file and save it to the cache. // Then have it load the file contents before returning its exports // object.Module._load(filename, this){ If(fileNamein Module._cache) Return Module._cache[filename];
  var module = new Module(filename, parent);   Module._cache[filename]= module;   Module.load(filename);
  // 先把模塊放到緩存然后再去加載內容,可以解決循環(huán)依賴的問題。
  // 參見https://nodejs.org/api/modules.html的Cycles部分。
  return module.exports; } Module.prototype.load(filename){ var extension = path.extname(filename) || ‘.js’;
Module._extensions[extension](this, filename){ var content = fs.readFileSync(filename, ‘utf-8’); module._compile(content, filename);   } } // Run the file contents in the correct scope or sandbox. Expose // the correct helper variables (require, module, exports) to // the file. // Returns exception, if any.Module.prototype._compile = function(content, filename) { function require(path) { return self.require(path);   }   require.main= process.mainModule;   // Enable support to add extra extension types  require.extensions = Module._extensions;   require.cache= Module._cache;   // TODO: 每個模塊加載到自己的context中會有什么不同?   // Set the environ variable NODE_MODULE_CONTEXTS=1 to make node load allmodules in their own context.   // Module._contextLoad = (+process.env['NODE_MODULE_CONTEXTS'] > 0);   // if (Module._contextLoad) { .... }  // create wrapper function  var wrapper = NativeModule.wrap(content);   // wrapper = '(function (exports, require, module, __filename, __dirname) { ' + content + ' });'  // runInThisContext()可以認為是在某個上下文環(huán)境中執(zhí)行的eval()。   // compiledWrapper相當于eval(‘(function(){....})’)的結果,也就是真正的Function。  var compiledWrapper = runInThisContext(wrapper, { filename: filename });   // module.exports 和 exports 的區(qū)別:   // 這里只傳遞了exports的引用;而上面Module._load()返回的是module.exports,因此給module.exports賦值后,   // exports仍然指向之前的module.exports?! ar args = [self.exports, require, self, filename, dirname];   // 真正執(zhí)行compiledWrapper這個function,也就是執(zhí)行了filename.js的內容?! eturn compiledWrapper.apply(self.exports, args); }

runInThisContext()就是vm.js里的runInThisContext(),vm.runInThisContext()調用了src/node_contextify.cc中的RunInThisContext()。

https://github.com/joyent/node/blob/master/lib/vm.js

https://github.com/joyent/node/blob/master/src/node_contextify.cc

 擴展:

https://github.com/brianmcd/contextify

The main difference between Contextify and Node's vm methods is that Contextify allows asynchronous functions to continue executing in the Contextified object's context.

博客地址:http://www.cnblogs.com/jasonxuli/

分享名稱:nodejsjs模塊加載-創(chuàng)新互聯(lián)
鏈接分享:http://aaarwkj.com/article8/dspgop.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供面包屑導航外貿網站建設、品牌網站建設、企業(yè)建站、微信公眾號、網站設計公司

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

商城網站建設
av成人黄色片在线播放| 人人妻夜夜天天俺去添噜| 国产麻豆精品二区视频| 九九re久久这里有精品| 人妻中文字幕日韩av| 91精品国产高清91久久久久久 | 日本大片在线一区二区三区| 懂色av中文一区二区| 亚洲一区二区三区在线观看| 亚洲熟妇人妻一区二区三区| 日本免费一区二区三区手机在线 | 欧美福利免费在线视频| 成年人黄色免费网站在线观看| 日韩精品电影一区在线观看| 蜜桃福利视频一区二区| 在线亚洲精品一区二区| 国产一区国产二区中文字幕| 国产成人原创免费观看| 中文字幕成人资源网站| 国产三级传媒在线观看| 亚洲欧美日韩国产桃色| 国产精品大全中文字幕| 男人喜欢看的免费视频| 婷婷色综合一区二区三区| 巴西老熟女大奶子多毛逼| 亚洲码欧洲码一二三区| 国产亚洲精品第一最新| 五月婷婷六月丁香在线观看| 最美是你免费视频观看| 91白丝视频在线观看| 五十路六十路美熟人妻| 日本韩国欧美成人精品| 免费在线观看福利av| 黄片大全视频在线免费观看| 欧美日韩精品人妻二区| 国内校园性猛交视频网站| 丰满肥臀熟女高清区二区| 午夜性色福利视频你懂的| 丁香婷婷激情五月天综合| 香蕉网性欧美在线视频| 午夜福利视频在线一区|