I have two web pages (a.php and b.php). They have very similar logic, but a great interface. I wrote two javascript.
Both of them look like this:
aUI = { displayMessage = function ... showDetails = function ... } function foo() { aUI.displayMessage(); aUI.showDetails();
aUI.displayMessage () is different from bUI.displayMessage (). But a.js and b.js have the same foo ().
I extracted foo (). So now I have three .js: aUI.js, bUI.js and logic.js.
logic.js:
function foo() { UI.displayMessage(); UI.showDetails();
aUI.js and bUI.js:
UI = { displayMessage = function ... showDetail = function ... }
How can a.php know that it should use aUI.js? I wrote a simple tool:
<script type="text/javascript" src="aUI.js"></script> <script type="text/javascript" src="logic.js"></script>
It works, but it seems not smart. I duplicated the 'UI' namespace in the project.
Is there a better way?
Lai yu-hsuan
source share