試圖讓這個在JS創建工作:在對象引用變量使用自定義構造函數
var calculate = function(votesA, votesB, votesC) {
var total = votesA + votesB + votesC;
function Results(resultsA, resultsB, resultsC) {
this.resultsA = resultsA;
this.resultsB = resultsB;
this.resultsC = resultsC;
}
var curResults = new Results(votesA, votesB, votesC);
curResults.resultsA = (votesA/total) x 100;
curResults.resultsB = (votesB/total) x 100;
curResults.resultsC = (votesC/total) x 100;
console.log(curResults.resultsA, curResults.resultsB, curResults.resultsC);
}
calculate(5,4,8);
calculate(5,6,8);
calculate(6,8,9);
不知道爲什麼它不工作,但我覺得這是值得做的怎麼樣我參考curResults中的變量
你能告訴我們你想做什麼嗎? – polin