window.onload = function(){
console.log(require("weekDay").name(new Date().getDay()));
}
//require对象
function require(name) {
//1.根据名称解析文件,返回代码
var code = new Function("exports",readFile(name));
var exports = {};
//2.执行代码,返回对象
code(exports);
return exports;
}
//模拟require对象查找文件机制
function readFile(name) {
return readFile.files[name] || "";
}
readFile.files = {
weekDay:' var names = ["周日","星期一","星期二","星期三","星期四","星期五","周六"]; \
exports.name = function(number){return names[number]\
}; \
exports.number = function(name){return names.indexOf(name);\
} '
}