There is a super simple way to do this, along the lines of sowbug's answer, but which doesn't need any XHR or file reading.
Step 1.
Create resource/config.js like so:
gOptions = {
// This can have nested stuff, arrays, etc.
color: 'red',
size: 'big',
enabled: true,
count: 5
}
Step 2.
Include this file in your index.html:
<!doctype html>
<head>
<script src="resource/config.js"></script>
...
Step 3.
Access your options directly from your main.js (or anywhere):
...
if (gOptions.enabled) {
for (var i = 0; i < gOptions.count; i++) {
console.log(gOptions.color);
}
}
...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…