Quy tắc đặt tên trong Javascript

Lại Đình Cường

Tài liệu thiết kế website

Quy tắc đặt tên áp dụng trong khi viết mã Javascript.

// Naming Rules in Javascript

// Variables
let fullName = "Lai Dinh Cuong";

// Boolean variables
let isStudent = false;
let hasMoney = false;

// Functions
function getInfo() {
    return "ABC";
}

// Constants
const HEIGHT = 1720;
const BIRTH_DAY = 19900924;

// Classes
class SleepCalculator {
    constructor(bedtime, wakeupTime) {
        this.bedtime = bedtime;
        this.wakeupTime = wakeupTime;
    }

    getInfo() {
        return [
            this.bedtime,
            this.wakeupTime
        ]
    }
}

let calculator = new SleepCalculator("21:45", "05:30");
console.log(calculator.getInfo());

// Private functions
class Cat {
    constructor(name, color, numLegs) {
        this.name = name;
        this.color = color;
        this.numLegs = numLegs;
        this.detail = this._getName();
    }

    _getName() {
        return this.name + ", legs: " + this.numLegs + ", color: " + this.color;
    }
}

let cat = new Cat("Tom", "white", 4);
console.log(cat);

 

0 0 đánh giá
Đánh giá bài viết
Theo dõi
Thông báo của
guest
0 Góp ý
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất