JavaScript Object Property Descriptors

  Рет қаралды 15,851

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

When you create an Object and add properties there are actually six property descriptors that you can use to define qualities of the property that you have added.
DATA property descriptors are
value
writable
configurable
enumerable
ACCESSOR property descriptors are
configurable
enumerable
get
set
You can use these property descriptors in combination with a collection of Object methods to fine tune access to your properties and their value.
See the comments in the Code Gist for a list of all the property descriptors and the Object methods.
Code GIST: gist.github.co...

Пікірлер
@jiharedconteh4530
@jiharedconteh4530 Жыл бұрын
The explanation is breathtaking. It’s so simplified.😊
@Brad_Script
@Brad_Script Жыл бұрын
there's specific interactions between writable and configurable described on the MDN website: if writable = true and configurable = (true or false), you can modify a property with both the "value" attribute and directly on the object via dot or bracket syntax if writable = false and configurable = true, you can modify a property only with the "value" attribute but not with dot/bracket syntax if writable = false and configurable = false, the property cannot be modified in any way also if configurable is set to false, you can only modify writable from true to false, but not false to true
@rotrose7531
@rotrose7531 4 жыл бұрын
Your tutorials deserves any amount you would request, I learned a lot of tutorials so far, paid and free, but your style is impeccable. after following your tutorials for about a week or so, I am now confident to pick up again the project I left halfway because of its complexity. Thank you.
@paulgz101
@paulgz101 4 жыл бұрын
13 minutes and you know everything about Object Descriptors. The best JS stuff on youtube. Thanks a lot! Спасибо! Obrigado! Tack! Gracias! Danke schön! Merci!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
You're welcome. Ничего. De nada. Varsågod. De nada. Bitte. De rien.
@GGGGGGGGGG96
@GGGGGGGGGG96 4 жыл бұрын
There are many many front-end developers, but very few are really interested on PropertyDescriptors, so I am happy to join this very exclusive club :D
@fs17792
@fs17792 3 жыл бұрын
Danke!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Vielen Dank!
@anujkumarjha9454
@anujkumarjha9454 3 жыл бұрын
best explanation with source code provided. I mastered this in only 13 minutes. thank you so much.
@kensleylewis
@kensleylewis 4 жыл бұрын
Love the video notes on Object. Very helpful!
@jeff-creations
@jeff-creations Жыл бұрын
Thanks for sharing your knowledge on this topic Steve. I have one question though: this.value is greyed out on the set function when I copied over your code, but it did log correctly. When I configured the get/set like this the "this.value" wasn't greyed out on the set() and logged correctly as well: Object.defineProperty(obj, 'frank', { configurable:true, enumerable: true, get() { return this.value }, set(val) { this.value = val + " baby!"; } }); I'm not using modules, just plain HTML and JS. Have any idea why this.value would be greyed out?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
Could be an issue with how your linter is configured. Could be the context of `this` inside of where the code is being run.
@jeff-creations
@jeff-creations Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Thanks for the reply/insight Steve. I am still learning the "this" keyword flowchart! You rock man!
@davidhiudianto9863
@davidhiudianto9863 3 жыл бұрын
Thank you for another great tutorial! One question though, at 8:00, when we're using arrow function, doesn't `this` resolve to module.exports? And therefore `this.value = _val + " baby!"` will define another property named `value` inside module.exports? Thank you sir, your js tutorials really helped me alot..
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Good question. The `this` inside the Object.defineProperty method will use the first parameter of that method as the value of `this`. Object.defineProperty(obj, 'frank', { }) So, in this code, `obj` will be used as the `this` context.
@davidhiudianto9863
@davidhiudianto9863 3 жыл бұрын
​@@SteveGriffith-Prof3ssorSt3v3 Thanks for your reply...Out of curiosity, I did an experiment on this one, stackblitz.com/edit/node-4djxlf. I think the arrow function is the culprit here, it has indeed changed the `this` context, and if regular function keyword is used, `obj` will be correctly used as `this` context inside the get and set. What do you think? Thank you so much.
@codewithsheikh2805
@codewithsheikh2805 Жыл бұрын
​@@SteveGriffith-Prof3ssorSt3v3 actually no. Since you are using the arrow function 'this' in that case will be window object if you're not strict mode in browser and since node runs in something like module it will create new object property on that module object. you can recreate it yourself and see the output or see output of program I have given both with and without arrow function. const obj = {}; // Object.defineProperty(obj, 'a', { // value: 'one', // writable: true, // enumerable: true, // configurable: true // }); // Object.defineProperty(obj, 'foo', { // get: () => console.log(this) // , // set: (name) => { // this.value = name; // }, // enumerable: true, // configurable: true // }); Object.defineProperty(obj, 'a', { value: 'one', writable: true, enumerable: true, configurable: true }); Object.defineProperty(obj, 'foo', { get: () => console.log(this) , set(name) { this.value = name }, enumerable: true, configurable: true }); console.log(obj) obj.foo = 'falan' obj.foo; console.log(obj)
@priyaranjan1733
@priyaranjan1733 6 жыл бұрын
thank you sir for splendid explanation.. I was very much confused about these jargon phrases
@Snoo29293
@Snoo29293 4 жыл бұрын
Another great tutorial, your videos are helping me a lot.
@Behold-the-Florist
@Behold-the-Florist 2 жыл бұрын
Your content is priceless! Thank you so much Sir! ;)
@alfaex.
@alfaex. 4 жыл бұрын
AMAZING video Steve
@nicolascondrea8068
@nicolascondrea8068 2 жыл бұрын
Brilliant tutorial, thank you!
@chesterxp508
@chesterxp508 3 жыл бұрын
Another very cool tutorial !!!
@deylenergy5761
@deylenergy5761 6 жыл бұрын
Thanks for an explicit explanation.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
Hope it helps.
@shaikzuhair8537
@shaikzuhair8537 4 жыл бұрын
Thanks you for good explanations
@GursewakSingh-gx6ev
@GursewakSingh-gx6ev 4 жыл бұрын
The side of Javascript that I have never seen...Thanks, Steve for such fine, granular knowledge about JavaScript. Just one question: Are you a professor ??
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Yes I am.
@GursewakSingh-gx6ev
@GursewakSingh-gx6ev 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Then I have a huge Respect for you, just keep us alive with these core things concept which is either poorly taught or not taught. Please make a series of testing.
@AshokKumar-dp5rv
@AshokKumar-dp5rv 5 жыл бұрын
Thanks man! Grate explanation and easy to understand.
@sineava
@sineava 4 жыл бұрын
awesome video,thank you very much!
@eh-lo2do
@eh-lo2do 4 жыл бұрын
Thank you brother, sure clear and easy to understand, one question what is it with _val, is it just a naming convention ?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Yes. It is my local variable being passed into the function. Helps to avoid confusion between things like name and _name or value and _value.
@kensleylewis
@kensleylewis 4 жыл бұрын
Do you have lesson on factory functions?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
I made this one a few years ago - kzbin.info/www/bejne/i5TQgnWoe7x3rpY
@zohar10001000
@zohar10001000 4 жыл бұрын
beautifully explained, thanks.
@romeojoseph766
@romeojoseph766 Жыл бұрын
isn't creating a property with Object.defineProperty tedious for the long term?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
It's not for everyday object creation. Its for special cases where you need to alter the default values of the property descriptors.
@justincook8473
@justincook8473 5 жыл бұрын
Phenomenal video! Thank you!
@oluface2
@oluface2 6 жыл бұрын
Sir Please Why did you add the " prop " in the for loop?
@priyaranjan1733
@priyaranjan1733 6 жыл бұрын
is 'prop' a keyword? , #SameConfusion
@jordanski5421
@jordanski5421 4 жыл бұрын
prop is just a variable he could've called it anything
@yinonelbaz5309
@yinonelbaz5309 2 жыл бұрын
great tutorial!!!
@oghenefokethompson7407
@oghenefokethompson7407 4 жыл бұрын
Thanks sir.
@PauloSantos-yu1tn
@PauloSantos-yu1tn 5 жыл бұрын
This video is very good stuff. Thanks
@sampathkumarajjapaga9817
@sampathkumarajjapaga9817 5 жыл бұрын
😍 This is what I'm looking for
@dharanyuvi6951
@dharanyuvi6951 4 жыл бұрын
Thanks dude., it really means a lot!!
@picardibenge2498
@picardibenge2498 2 жыл бұрын
very clear
@bardhan.abhirup
@bardhan.abhirup 4 жыл бұрын
Thanks a lot!
@ck0024
@ck0024 4 жыл бұрын
200th like from me
@md.sahaibmridha3170
@md.sahaibmridha3170 4 жыл бұрын
Cool man!
@ajeetworking
@ajeetworking 5 жыл бұрын
thank you
@dharanyuvi6951
@dharanyuvi6951 4 жыл бұрын
Thanks dude., it really means a lot!!
Private Variables in JavaScript
8:30
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 12 М.
Understanding the Keyword THIS in JavaScript
13:59
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 9 М.
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН
Their Boat Engine Fell Off
0:13
Newsflare
Рет қаралды 15 МЛН
Every team from the Bracket Buster! Who ya got? 😏
0:53
FailArmy Shorts
Рет қаралды 13 МЛН
Javascript Objects Explained | Javascript Objects Tutorial
23:17
ES5 Custom Object Methods, Getters, and Setters
9:49
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 12 М.
ООП в JavaScript. Get, Set JavaScript, приватные и защищенные свойства
23:01
WebDev с нуля. Канал Алекса Лущенко
Рет қаралды 48 М.
Getter and setter properties in JavaScript
17:18
procademy
Рет қаралды 8 М.
ES6 Iterator & Generator Fundamentals
18:18
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 31 М.
JS Function Methods call( ), apply( ), and bind( )
13:14
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 38 М.
Reacting to Controversial Opinions of Software Engineers
9:18
Fireship
Рет қаралды 2,1 МЛН
8 Rules For Learning to Code in 2025...and should you?
12:59
Travis Media
Рет қаралды 94 М.
Object In JavaScript | JavaScript Object Tutorial For Beginners
16:36