C-log

JS의 핵심! Object 오브젝트 본문

📒JS/⚡ver.1

JS의 핵심! Object 오브젝트

4:Bee 2023. 5. 16. 12:01
728x90

 YouTube Link
 
자바스크립트 7. 오브젝트 넌 뭐니? | 프론트엔드 개발자 입문편 (JavaScript ES6)
https://youtu.be/1Lbr29tzAA8

 

//1.리터럴과 프로퍼티
//object = {key : value}
const name = 'ellie';
const age = 4;

function print(name, age) {
  console.log(name);
  console.log(age);
}

print(name, age);

//=>관리하기 힘들다, 오브젝트로 변환하면 아래와 같다.
const ellie = { name: 'ellie', age: 4 };

function print(person) {
  console.log(person.name);
  console.log(person.age);
}

print(ellie);

const obj1 = {};//object literal
const obj2 = new Object();//object constructor

 

//1. 정해진 프로퍼티
function makePerson(name, age) {
  return {
    name,
    age,
  };
}

const person = makePerson('elile', 30);
console.log(person);

//2. constructor function
function Person(name, age) {
  this.name = name;
  this.age = age;
}
const person2 = new Person('elile', 30);
console.log(person);

//3. for..in / for..of
for (key in ellie) {
  console.log(key);
}

const array = [1, 2, 3, 4];
for (value of array) {
  console.log(value);
}

//4. cloning
const user = { name: 'elile', age: 20 };
const user2 = user;
user2.name = 'coder';
console.log(user);
728x90

'📒JS > ⚡ver.1' 카테고리의 다른 글

JS의 핵심 : ERD  (0) 2023.05.22
JS의 핵심! 프로토타입 prototype  (0) 2023.05.16
JS의 핵심! Array 배열  (0) 2023.05.12
JS의 핵심! 콜백 함수  (0) 2023.05.10
JS의 핵심! 배열 관련 함수  (0) 2023.05.10
Comments