
ReflectionMethod::hasPrototype은 PHP에서 메서드가 프로토타입 메서드를 가지고 있는지 여부를 확인하는 메서드입니다. 프로토타입 메서드는 상위 클래스의 메서드를 재정의하거나 확장하는 메서드를 의미합니다.
자바스크립트에서 Prototype Chain은 객체의 프로토타입 체인을 의미합니다. 객체의 프로퍼티나 메서드가 없을 때, 프로토타입 체인에서 검색됩니다. 자바스크립트에서 프로토타입 체인은 다음과 같이 구현됩니다.
#hostingforum.kr
javascript
function Person(name) {
this.name = name;
}
Person.prototype.sayHello = function() {
console.log(`Hello, my name is ${this.name}`);
};
function Student(name, age) {
Person.call(this, name);
this.age = age;
}
Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;
Student.prototype.sayHello = function() {
console.log(`Hello, my name is ${this.name} and I'm ${this.age} years old.`);
};
const student = new Student('John', 20);
student.sayHello(); // Hello, my name is John and I'm 20 years old.
위 예제에서 Student.prototype.sayHello()는 Person.prototype.sayHello()를 재정의한 프로토타입 메서드입니다. 이 경우 ReflectionMethod::hasPrototype은 true를 반환합니다.
반면에 Student.prototype.sayHello()가 Person.prototype.sayHello()를 확장하지 않는 경우, ReflectionMethod::hasPrototype은 false를 반환합니다.
#hostingforum.kr
javascript
Student.prototype.sayHello = function() {
console.log('Hello, I'm a student.');
};
이 경우 ReflectionMethod::hasPrototype은 false를 반환합니다.
2025-07-29 07:06