我正在使用math.js,我想addFive在數(shù)組的每個元素上調(diào)用該方法x。如果我調(diào)用addFive類似的變量y,則效果很好。我得到的輸出為10。x = math.matrix([2,3,4]);let y= 5;function example(){ this.a=5; this.addFive = function(x){ return (x+this.a); }}ex = new example();let w = ex.addFive(y);console.log(w);當(dāng)我嘗試這個let w = math.map(x, addFive);console.log(w);我得到一個錯誤addFive is not defined。有沒有不使用循環(huán)的解決方法?
如何在數(shù)組上調(diào)用對象方法?
慕桂英3389331
2021-04-09 18:15:54