04.quiz

์ฐธ์กฐ์œ„์น˜๋Š” ๊ทธ๋Œ€๋กœ ๋‘๊ณ  ์•ˆ์— ์žˆ๋Š” ๋‚ด์šฉ์„ ๋น„์šฐ๊ธฐ

var something = [1, 2, 3, 4, 5];
something.length = 0;

๊ฒฐ๊ณผ๋Š”?

var a = {};
var output = {function() {
  delete x;
  return x;
}}();

console.log(a);

delete๋Š” ๊ฐ์ฒด์—์„œ key, value๋ฅผ ์ง€์šธ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ์šฉ๋„๊ฐ€ ์ž˜๋ชป์“ฐ์—ฌ์ ธ ์žˆ๋‹ค.

๊ฒฐ๊ณผ๋Š”?

var Employee = {
    company: 'xyz'
}

var emp1 = Object.create(Employee);
// emp1 = {}
// __proto__ : company: 'xyz';
delete emp1.company;
// emp1์— ์žˆ๋Š” company๋ฅผ ์ง€์šธ๋ ค๊ณ  ํ•˜๋Š”๋ฐ emp1์— ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. 
// delete emp1.__proto__.company
// ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด Employee์— ์žˆ๋Š”๊ฒŒ ์ง€์›Œ์ง„๋‹ค. ์†Œ๋ฆ„.. 
console.log(emp1.company);

๊ฐ์ฒด ๋งŒ๋“ค๊ธฐ

  1. 'new' ํ‚ค์›Œ๋“œ

  2. ์˜ค๋ธŒ์ ํŠธ ๋ฆฌํ„ฐ๋Ÿด {}

  3. Object.create();

this๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€?

function myFunc() {
  console.log(this.message);
}
myFunc.message = 'Hi John';

console.log(myFunc()) // this๋Š” window๊ณ  console์—” undefined

What will be logged?

function Person(names, age){
  this.names = name || "John";
  this.age = age || 24;
  this.displayName = function () {
    console.log(this.names);
  };
}

Person.names = "John2";
Person.displayName = function () {
  console.log(this.names);
};

var person1 = new Person("John3");
person1.displayName();
Person.displayName();
function passWordMngr() {
  var password = '12345678';
  this.userName = 'John';
  return {
    pwd: password
  };
}
var userInfo = passWordMngr();
console.log(userInfo.pwd); // '12345678'
console.log(userInfo.userName); // undefined

Last updated

Was this helpful?