JavaScript 70 – progetto di un linguaggio di programmazione – 5

Arrays Add support for arrays to Egg by adding the following three functions to the top scope: array(...) to construct an array containing the argument values, length(array) to get an array’s length, and element(array, n) to fetch the nth element from an array.

Non è banale, meglio sbirciare i suggerimenti: The easiest way to do this is to represent Egg arrays with JavaScript arrays.

The values added to the top environment must be functions. Array.prototype.slice can be used to convert an arguments array-like object into a regular array.

// Since the code for most chapter in Eloquent JavaScript isn't
// written with node's module system in mind, this kludge is used to
// load dependency files into the global namespace, so that the
// examples can run on node.
module.exports = function() {
for (var i = 0; i < arguments.length; i++)
(1,eval)(require("fs").readFileSync(__dirname + arguments[i], "utf8"));
};