Code Monkey home page Code Monkey logo

Comments (4)

choibyeol avatar choibyeol commented on August 21, 2024

Q1. ?에 들어갈 값은 무엇일까요? 오버라이딩과 프로퍼티 섀도잉에 대해서도 설명해 주세요.

const Person = (function () {
function Person(name) {
	this.name = name;
	}

Person.prototype.sayHello = function() {
	console.log(`Hi! My Name is ${this.name}`);
	}

return Person;
}());

const me = new Person('Lee');

me.sayHello = function() {
	console.log(`Hey! My Name is ${this.name}`)
}

me.sayHello(); // ?
정답
Hey! My Name is Lee
오버라이딩은 상위 클래스가 가지고 있는 메서드를 하위 클래스가 재정의하여 사용하는 방식을 말한다. 프로퍼티 섀도잉은 상속 관계에 의해 프로퍼티가 가려지는 현상을 말한다.
인스턴스 메서드 sayHello는 프로토타입 메서드 sayHello를 오버라이딩 했고, 프로토타입 메서드 sayHello는 프로퍼티 섀도잉에 의해 가려지기 때문에 me 객체의 sayHello가 동작한다.

from js-deep-dive-study.

SDWoo avatar SDWoo commented on August 21, 2024

Q1. 다음 코드의 결과를 쓰시오

function Study(subject) {
  this.subject = subject
}
Study.prototype.getStudySubject = function () {
  console.log(`Today's Study is ${this.subject}`);
}

Study.person = 'dongwoo';
Study.getPerson = function () {
  console.log(this.person)
}
const jsStudy = new Study('javaScript');
Stduy.getPerson(); // -> ?
jsStudy.getPerson();  // -> ?
정답 1. dongwoo
  1. TypeError

생성자 함수에 직접 추가한 정적 프로퍼티나 메소드는
생성자 함수로만 참조/호출할 수 있다.

from js-deep-dive-study.

 avatar commented on August 21, 2024

Q1. 출력된 결과와 이유를 적어주세요

function Person(name) {
   this.name = name
}

const me = new Person('Lee')

console.log(me instanceof Person); // <- 1.
console.log(me instanceof Object); // <- 2.
정답
1. Person.prototype이 me 객체의 프로토타입 체인 상에 존재하므로 true로 평가됨 2. Object.prototype이 me 객체의 프로토타입 체인 상에 존재하므로 true로 평가됨

from js-deep-dive-study.

Heojiyeon avatar Heojiyeon commented on August 21, 2024

Q1. __ proto __ 접근자 프로퍼티를 코드 내에서 직접 사용하는 것을 권장하지 않는 이유를 설명해주세요.

정답
직접 상속을 통해 Object.prototype을 상속받지 않는 객체를 생성할 수도 있어, 모든 객체가 __proto__ 접근자 프로퍼티를 사용할 수 없기 때문이다

Q2. 프로토타입 체인에 대해 설명해주세요.

정답
객체의 프로퍼티에 접근하려고 할 때 해당 객체에 접근하려는 프로퍼티가 없다면 [[Prototype]] 내부 슬롯의 참조를 따라 자신의 부모 역할을 하는 프로토타입의 프로퍼티를 순차적으로 검색하는데, 이를 프로토타입 체인이라고 한다.

from js-deep-dive-study.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.