Câu hỏi

Kết quả đoạn code sau là gì?

class Chameleon {
    static colorChange(newColor) {
      this.newColor = newColor;
      return this.newColor;
    }

    constructor({ newColor = "green" } = {}) {
      this.newColor = newColor;
    }
  }

  const freddie = new Chameleon({ newColor: "purple" });
  freddie.colorChange("orange");
  • A: orange
  • B: purple
  • C: green
  • D: TypeError

Câu trả lời

Đáp án: D

Hàm colorChange là một hàm static (hàm tĩnh). Hà...

Bạn cần đăng nhập để xem