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

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)

商城網站建設
人妻少妇被猛烈进入中出视频| 99精品欧美一区二区三区视频| 巴西老熟女大奶子多毛逼| 国产黄色av网站在线| 日本人免费一区二区电影| 最新日韩欧美一区二区| 尤物视频精品在线观看| 青青草成人一区二区三区| 亚洲av乱码国产精品观看| 国产久精品热看久品热久热| 成年自拍视频在线观看| 欧美日韩另类中文字幕| 国产三级成人在线视频| 中文字幕久久亚洲一区| 成人午夜欧美熟妇小视频| 另类亚洲欧美专区第一页| 高清不卡av在线播放| 中文字幕日韩一区二区| 一区二区亚洲免费的视频| 成人黄色av网站在线观看| 黑人巨大精品欧美一区免| 人妻伦理一区二区三区| 欧美特黄大片在线观看| 东京热一精品无码av| 久久精品国产亚洲av麻豆她| 免费日韩黄片在线观看| 午夜精品一区二区三区久久| 久久亚洲一区二区麻豆偷| 农村人妻一区二区三区视频 | 97在线观看免费公开| 亚洲精品紧身裙女教师av| 欧美日韩国产成人激情| 欧美性精品不卡在线观看| 丰满人妻一区二区三区色| 性感美女国产精品一区二区| 亚洲成人精品久久久| 成人在线一区二区三区观看| 国产一区欧美二区日韩三区| 色婷婷综合激情一区二区| 日本一区二区精美视频| 老湿机午夜在线免费观看|