У нас вы можете посмотреть бесплатно Learn JavaScript STATIC keyword in 8 minutes! ⚡ или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
// static = keyword that defines properties or methods that belong // to a class itself rather than the objects created // from that class (class owns anything static, not the objects) // ----------- EXAMPLE 1 ----------- class MathUtil{ static PI = 3.14159; static getDiameter(radius){ return radius * 2; } static getCircumference(radius){ return 2 * this.PI * radius; } static getArea(radius){ return this.PI * radius * radius; } } console.log(MathUtil.PI); console.log(MathUtil.getDiameter(10)); console.log(MathUtil.getCircumference(10)); console.log(MathUtil.getArea(10)); // ----------- EXAMPLE 2 ----------- class User{ static userCount = 0; constructor(username){ this.username = username; User.userCount++; } static getUserCount(){ console.log(`There are ${User.userCount} users online`); } sayHello(){ console.log(`Hello, my username is ${this.username}`); } } const user1 = new User("Spongebob"); const user2 = new User("Patrick"); const user3 = new User("Sandy"); user1.sayHello(); user2.sayHello(); user3.sayHello(); User.getUserCount();