Help us understand the problem. What is going on with this article?

【JavaScript 】クラス

More than 1 year has passed since last update.

クラス

'use strict';

class Player { // クラス名は慣習的に大文字から始める

    constructor(name, score) { // コンストラクター
        // プロパティ
        this.name = name;
        this.score = score;
    }

    // メソッド
    showScore() {
        console.log(` score = ${this.score}`);
    }

    // 静的メソッド
    static showVersion() {
        const version = '1.0';
        console.log(`Player class ver. ${version}`);
    }
}

// インスタンス
const player1 = new Player("player1", 10);

// プロパティ
console.log(player1.name); // player1

// メソッド
player1.showScore(); // score = 10

// 静的メソッド
Player.showVersion(); // Player class ver. 1.0

※Google Chrome で確認
※ES8

devmk3
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away