동적으로 생성 된 객체를 JavaScript의 배열에 전달하려고합니다. 개체가 전달되지만 개체 내부의 데이터를 검색하려고하면 사라집니다. 콘솔에 [object, object]가 기록됩니다. 이 일을 어떻게 할 수 있습니까? 당신이 개체에 액세스하려고하고 있지만 var savedRounds = [];
의 var
이 savedRounds는 로컬 범위 및 roundList
방법 내부에서만 액세스 할 의미 어디JavaScript의 배열에 객체 전달
function roundList(myRounds){
var savedRounds = [];
savedRounds.push(myRounds);
console.log("this is savedRounds " + savedRounds);
};
function round(course,tee,slope,rating,score){
this.course=course;
this.tee=tee;
this.slope=slope;
this.rating=rating;
this.score=score;
}
function makeRound(){
var newCourse = document.getElementById('course').value
var newTee = document.getElementById('tee').value
var newSlope = document.getElementById('slope').value
var newRating = document.getElementById('rating').value
var newScore = document.getElementById('score').value
var newDate = document.getElementById('date').value
var newRound = new round(newCourse,newTee,newSlope,newRating,newScore);
roundList(newRound);
}
... "roundList"가 반환되면 배열이 사라짐을 의미합니다. – Pointy