dimanche 29 mars 2015

Node won't run example from Eloquent Javascript, v8 will. What's the deal?

The function below is copied verbatim from Ch. 10 of Eloquent Javascript, and it runs perfectly with the v8 interpreter. However, it bombs out in Node with the object weekDay undefined. It also runs fine in the sandbox interpreter provided by the book. Can someone explain what's up?



(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")));

Aucun commentaire:

Enregistrer un commentaire