
const obj={};
console.log(Object.getPrototyoeOf(obj) === Object.prototype); // true
In JavaScript, the concept of the prototype is fundamental to how objects inherit behavior from each other.
[[Prototype]]). Object.prototype).const obj = { ... };), its internal [[Prototype]] is Object.prototype by default (unless you use special methods like Object.create to change this). toString or hasOwnProperty from Object.prototype.Object.createObject.create(proto). [[Prototype]] is explicitly set to proto. const animal = {
move() { console.log("I am moving!"); }
};
const cat = Object.create(animal);
cat.move(); // "I am moving!"cat doesn’t have move itself, but its prototype is animal, which has move.class Person {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hello, my name is ${this.name}`);
}
}
const bob = new Person("Bob");Person.prototype as the place where greet is stored, and bob’s internal [[Prototype]] pointing to Person.prototype.prototype: 함수 객체가 가지는 프로토타입 객체에 대한 참조constructor: 프로토타입 객체가 자신을 생성한 constructor function 을 가르키는 속성 __proto__는 객체의 프로토타입에 접근하는 비표준 방법주의:
__proto__는 deprecated => Object.getPrototypeOf() 사용 권장
function Person(name){ //함수객체
this.name =name;
}
const person = new Person("Alice"); //new 키워드로 instance 화
console.log(Object.getPrototypeOf(person) === Person.prototype); //true
console.log(Person.prototype.constructor === Person);
function Person(name) {
this.name = name;
}
Person.prototype.greet = function () {
console.log(`Hello, my name is ${this.name}`);
};
let alice = new Person("Alice");Person is a constructor function. alice automatically has its internal [[Prototype]] pointing to Person.prototype. alice can use the greet method that’s defined on Person.prototype..prototype object to make them available to all instances created by that constructor. Person.prototype.sayGoodbye = ... will make sayGoodbye available to every Person instance, including those created before the method was added (as they share the same prototype).null at the top of the chain.When you see something like XMLHttpRequest.prototype, that object is where all the shared functionality for XMLHttpRequest instances is defined. Each instance you create with new XMLHttpRequest() inherits its methods from XMLHttpRequest.prototype via the prototype chain.
본 후기는 [한글과컴퓨터x한국생산성본부x스나이퍼팩토리] 한컴 AI 아카데미 (B-log) 리뷰로 작성 되었습니다.
#한컴AI아카데미 #AI개발자 #AI개발자교육 #한글과컴퓨터 #한국생산성본부 #스나이퍼팩토리 #부트캠프 #AI전문가양성 #개발자교육 #개발자취업