Загрузка страницы

JavaScript Getters and Setters Explained

In this tutorial we'll take a look at JavaScript Getters and Setters and see how you can use them with both the ES6 Class syntax and also with the more traditional way to define JavaScript classes.

You might also want to check out the video on the JavaScript 'this' keyword to see how that works: https://youtu.be/apE-9SEKxzE

JavaScript Getters and Setters Explained
-----------------------------------------------------------------
00:00 Introduction
00:46 Creating a new Class
01:41 Adding a setter
03:09 Adding a getter
03:27 Adding value to Getters and setters
06:53 Non-ES6 getters and setters
07:24 Using Object.defineProperty

— Follow Me —
Twitter: https://www.twitter.com/codebubb
Facebook: https://www.facebook.com/juniordevelopercentral/
Blog: https://www.juniordevelopercentral.com/
— Thanks! —

So in this JavaScript tutorial we'll take a look at how, with a basic JavaScript class definition, you can create custom behaviour for when you assign properties to an object and also retrieve their values.

We'll start of the tutorial with a simple bit of code that demonstrates how classes can be used to create new JavaScript objects and assign properties to the new object that is created.

We'll then define custom behaviour for our object's properties, adding validation for when we assign a new value to a property and also returning a different value for a property that has already been assigned a value.

Once we've taken a look at the ES6 getters and setters on a class, we'll see how this works with the older, more traditional way of assigning new properties to a class with a function constructor in JavaScript.

Check out some more Junior Developer Central JavaScript tutorials on the rest of the channel.

Видео JavaScript Getters and Setters Explained канала Junior Developer Central
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
6 сентября 2020 г. 21:00:01
00:09:59
Яндекс.Метрика