如何将三角形数组放在外面以便我可以使用它

时间:2015-04-29 05:50:45

标签: javascript arrays closures

我正在将一些ID存储到数组中。数组已正确填充,但我无法将其记录到外部也无法使用它。我有点困惑。这是我的代码,

的JavaScript

function storeTriangle() {
    var triangle = [];
    return function storePolygons() {
        for (var i = 0; i < 31; i++) {
            triangle[i] = s.select("#triangle36_" + (224 - i) + "_");
        }
    };
    storePolygons();
};
var polygons = storeTriangle();
polygons();

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
function storeTriangle() {
        var triangle = [];
        return function() {
            for (var i = 0; i < 31; i++) {
                triangle[i] = s.select("#triangle36_" + (224 - i) + "_");
            }
          return triangle;
        };
    };
    var polygons = storeTriangle();
    var triangle=polygons();
console.info(triangle)
&#13;
&#13;
&#13;