我發現這個代碼,我無法從this passage of Eloquent JavaScript明白:如何從Eloquent JavaScript中「導出」?
(function(exports) {
var names = [" Sunday ", " Monday ", " Tuesday ", " Wednesday ",
" Thursday ", " Friday ", " Saturday "];
exports.name = function(number) {
return names[number];
};
exports.number = function (name) {
return names.indexOf (name);
};
})(this.weekDay = {});
console.log(weekDay.name(weekDay.number("Saturday")));
特別是,我無法理解this.weekDay
:什麼是this
這裏? 以及我們如何訪問weekDay.name
- 它在函數的範圍內,所以我們如何從函數中訪問它?