2015-05-21 24 views
0

這是我想通過jsc在終端上運行的JavaScript:訪問功能(原型擴展名),另一個函數裏 - 使用Javascript

calc_real_weights.js:

getElementWithLowestCount(someMatrix) 

Array.prototype.max = function() { 
    return Math.max.apply(null, this); 
}; 

Array.prototype.min = function() { 
    return Math.min.apply(null, this); 
}; 

function getElementWithLowestCount(countAndWeightMatrix){ 
    aux = [] 
    for(var i = 0; i < countAndWeightMatrix.length; i++){ 
     if (countAndWeightMatrix[i][0] < aux.min()){ 
      var min = countAndWeightMatrix[i]; 
     } 
     aux.push(countAndWeightMatrix[i][0]); 
    } 
    return min; 
} 

錯誤:

Borjas-MacBook-Pro:Algorithm borjagvo$ jsc calc_real_weights.js 
Exception: TypeError: undefined is not a function (evaluating 'aux.min()') 
[email protected]_real_weights.js:37:46 
[email protected]_real_weights.js:46:45 
global [email protected]_real_weights.js:18:33 

它看起來像getElementWithLowestCount沒有看到數組原型擴展。我怎樣才能看到它?

謝謝。

回答

2

我認爲問題來自您在更改Array原型之前調用getElementWithLowestCount。嘗試將兩個Array.prototipe塊後的電話轉移到getElementWithLowestCount