![](/img/trans.png)
[英]Can someone please tell me how to remove or hide this JavaScript code?
[英]Can someone please tell me how to read the following: /\.(js)$/
我試圖了解一些我在網上找到的網絡服務器代碼,而“ else if”之后的部分是我唯一不了解的部分。 (我剛剛開始學習這些東西)。 謝謝
var path = url.parse(req.url).pathname; // Managing the root route if (path == '/') { index = fs.readFile(__dirname+'/public/index.html', function(error,data) { //do stuff... }); // Managing the route for the javascript files } else if( /\\.(js)$/.test(path) ) { index = fs.readFile(__dirname+'/public'+path, function(error,data) { //do stuff... });
它使您可以針對常規表達式進行測試。 這是MDN的工作原理。
在您的示例中,它正在檢查路徑是否以.js結尾
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.