[removed] Passing constructor as parameter, function instantiates only a single object

后端 未结 1 433
你的背包
你的背包 2021-01-28 04:32

I\'d like a certain function to create a grid and insert a unique object in each slot. The key here is, the function should accept the constructor as a parameter (as there can b

1条回答
  •  心在旅途
    2021-01-28 04:58

    Pass the buildNewObject as a function, instead of calling it and passing its result.

    function newGrid(rows,cols,dataFunction) {
        var customGrid = [];
        for (var row=0;row

    var myGrid = newGrid(3,3,buildNewObj); // no parenthesis, no invocation
    

    0 讨论(0)
提交回复
热议问题