比如有 article, product 兩個模塊
目錄結構:
- article
|---- index.html
|---- article.js
|---- article.css
- product
|---- index.html
|---- product.js
|---- product.css
載入任意模塊 index.html 都只讀取 app.js ,比如讀取 article/index.html 的時候,只想 article/article.js 裡的代碼,而 product/product.js 不要執行。
現在我的做法是:
1 / 在 article/index.html 的 <body> 上加入 class ,變成 <body class="body-article"> 。
2 / article/article.js 裡 寫上
if (!$_body.hasClass("body-article")) {
return false;
}
但感覺這樣的方法不規範,這導致 IDE (eg: PhpStorm) 不能很好的分析 js 之間的關係。請問怎樣的寫法才規範, IDE 能正常分析 js 呢?