Javascript/JS Flow
6-1. CLASS
헬크로스
2020. 1. 28. 00:00
CLASS
function Person(name, age){
this._name = name;
this._age = age;
}
// static method
Person.getInformations = function(instance){
return{
name: instance._name,
age: instance._age
};
}
// (prototype) method
Person.prototype.getName = function(){
return this._name;
}
// (prototype) method
Person.prototype.getAge = function(){
return this._age;
}
var injae = new Person('InJaEE', 20);
console.log(injae.getName()); // OK
console.log(injae.getAge()); // OK
console.log(injae.getInformations(injae)) // ERROR
console.log(Person.getInformations(injae)); // OK