6.7 ν¨μλ₯Ό μ¬μ©ν κ°μ²΄ μμ±
κ°μ²΄λ₯Ό νλμ© μ§μ λ§λ€μ΄ λ°°μ΄μ λ£μΌλ©΄ μλ‘ λ€λ₯Έ ννμ κ°μ²΄λ₯Ό λ°°μ΄ μμ λ£μ μ μλ€λ μ₯μ μ΄ μμ§λ§, λ²κ±°λ½κ³ , μ΄λ €μ°λ©° μκ°μ΄ μ€λ κ±Έλ¦°λ€. μ΄λ° κ³Όμ μ μ½κ² νκΈ° μνμ¬ νλμ 'ν'μ λ§λλ ν¨μλ₯Ό λ§λ€μ΄ λ§€κ°λ³μλ₯Ό λ°μ κ°μ²΄λ₯Ό λ§λ ν κ°μ²΄λ₯Ό 리ν΄μν¨λ€.
κ°μ²΄λ₯Ό μμ±νλ ν¨μμ κΈ°λ³Ένμ(1)
function makeStudent(name, korean, math, english, science) { var willReturn = { }; return willReturn; }
κ°μ²΄λ₯Ό μμ±νλ ν¨μμ κΈ°λ³Ένμ(2)
function makeStudent(name, korean, math, english, science) { var willReturn = { //μμ± μ΄λ¦: name, κ΅μ΄: korean, μν: math, μμ΄: english, κ³Όν: science, //λ©μλ getSum: function () { return this.κ΅μ΄ + this.μν + this.μμ΄ + this.κ³Όν; }, getAverage: function () { return this.getSum() / 4; }, toString: function () { return this.μ΄λ¦ + '\t' + this.getSum() + '\t' + this.getAverage(); } }; return willReturn; }
makeStudent()ν¨μλ₯Ό μμ±ν΄μ κ°μ²΄λ₯Ό μ°μ΄λ΄λ―μ΄ μμ°ν μ μλ€.
function makeStudent(name, korean, math, english, science) { /*μλ΅*/ } //νμμ 보 λ°°μ΄ μμ± var students = []; students.push(makeStudent('νκΈΈλ', 87, 99, 100, 50)); students.push(makeStudent('νκ°λ', 85, 92, 80, 90)); students.push(makeStudent('νμλ', 86, 93, 90, 80)); students.push(makeStudent('νμ λ', 83, 90, 10, 60)); //μΆλ ₯ var output = 'μ΄λ¦\tμ΄μ \tνκ· \n'; for (var i in students) { output += students[i].toString() + '\n'; } console.log(output);














