//8. 다른 파일 에서 함수 불러오기기
import { data } from "./example";
let updatedData = data;
updatedData.push(5);
console.log(updatedData);

//challenge
//두 수를 더해서 리턴하는 add 라는 함수를 다른 파일에다가 만들고
//index.js 에서 호출하여 사용해보기기
import { add } from './example'

let num = add(1,2)
console.log(num)

가장 많이 쓰이는 import 형식 Named Export

import {함수 이름} from '파일경로'

order.js

export const data = [1, 2, 3];

export function add(a, b) {
  return a + b;
}

문제

index.js 래스 불러와서 사용해보기

import { Animal } from "./example";
import { Cat } from "./example";

const a = new Animal("name", 5);
const b = new Cat();

b.makeNoise();
a.makeNoise();
console.log(Animal.return10());
console.log(a.metaData);

index.js

export class Animal {
  constructor(type, legs) {
    this.type = type;
    this.legs = legs;
  }
  makeNoise(sound = "Loud Noise") {
    console.log(sound);
  }
  get metaData() {
    return `Type: ${this.type}, Legs: ${this.legs}`;
  }
  static return10() {
    return 10;
  }
}
export class Cat extends Animal {
  makeNoise(sound = "meow") {
    console.log(sound);
  }
}