[μλ°μ€ν¬λ¦½νΈ] class
μ°Έκ³ μλ£: μΈνλ° μ½μ΄μλ°μ€ν¬λ¦½νΈ(ν΄λμ€ νΈ)
μ½μ΄ μλ°μ€ν¬λ¦½νΈ - μΈνλ° | κ°μ
ES6 μ΄μ κΉμ§μ μλ°μ€ν¬λ¦½νΈ μ 체λ₯Ό κ΄ν΅νλ ν΅μ¬ κ°λ λ€μ λνμ¬, μ λ°μ μΈ νλ¦μ μ΄ν΄λ³΄λ κ°μμ λλ€., π’ κ°μ 리λ΄μΌ μλ΄ 2021.8.26 리λ΄μΌ κ°μκ° μΉμ 0μ μ λ°μ΄νΈ λμμ΅λλ€. κΈ°μ‘΄
www.inflearn.com
ν΄λμ€
μΈμ€ν΄μ€λ€μ μμ ν΄λμ€μΈ μμ±μν¨μμ μμ±μν¨μμ λ©μλλ€
μΈμ€ν΄μ€λ μμ±μν¨μλ₯Ό μ§μ κ°μ§ λͺ»νλ€. μΈμ€ν΄μ€λ νλ‘ν νμ μ ν΅ν΄ μμλ‘ κ° μ μλ€.
function Person(name, age){
this._name = name;
this._age = age;
}
//μ€νν± λ©μλ - μμ±μν¨μμ λ©μλ
Person.getInformations = function(instance){
return{
name:instance._name,
age: instance._age
};
}
//νλ‘ν νμ
μ λ©μλ
Person.prototype.getName= function(){
return this._name;
}
Person.prototype.getAge=function(){
return this._age;
}
var roy = new Person('λ‘μ΄', age);
console.log(roy.getName());
console.log(roy.getAge());
console.log(roy.getInformations(roy)); //error
console.log(Person.getInformations(roy));
roy.getName(), roy.getAge()λ‘ νλ‘ν νμ μ ν΅ν΄ λ©μλλ₯Ό λΆλ₯΄λ 건 κ°λ₯νμ§λ§,
royμμ μμ±μν¨μμ static methodλ‘ λ°λ‘κ° μ μλ€. λ€λ§, ν¨μμ static methodμμ λ‘μ΄λ₯Ό λΆλ₯΄λ κ²μ κ°λ₯νλ€.