Understanding the Keyword THIS in JavaScript

  Рет қаралды 8,693

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

Пікірлер: 35
@rotrose7531
@rotrose7531 4 жыл бұрын
After giving up understanding this for many times, finally the concept becomes a little clearer, if not 100%, to me. Still, nobody else teaches JS as thoroughly as you, god-sent gift to me.Thank you very much.
@amgdeg4897
@amgdeg4897 2 жыл бұрын
how are you right now you were at the same place as me right now take a moment to reflect on how far you came
@andreiconstantinescu9830
@andreiconstantinescu9830 7 жыл бұрын
Thanks Steve, great content! I like it that you don't rush through the topic and keep it at a good pace, even for a ’newbie’. It takes empathy to do that. I’ll stick around :). Cheers, Andrei, RO
@aprilformosa
@aprilformosa 6 жыл бұрын
Hi, Steve, I've been trying to understand this keyword and studying numerous times, but still couldn't totally understand it. Your explanation is so easy to understand. I can't thank you enough.
@TrendRain
@TrendRain 3 жыл бұрын
If I encounter any concept(s) which are hard to understand, the first thing i search in youtube is "..... by steve griffith" and if I don't find anything, my first thought is, "Dammit, now I have to spend more time searching and understanding on my own." Great video as always.
@dyvaagna
@dyvaagna 2 жыл бұрын
I think this is the best explanation about 'this' in the entire internet, good job! You're an amazing teacher, hands down. just wanna ask, if we change the setTimeout(()=>{...}) to setTimeout(function(){....}), 'this' will log Window object. Is it because of setTimeout is part of Window object so it changed the context of 'this'? Thankyou.
@RajeshSahu-qp6cc
@RajeshSahu-qp6cc 4 жыл бұрын
Great video on 'this' keyword and so simple to understand. Thanks for this video Steve.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Thanks. You might like this video too - kzbin.info/www/bejne/m4iniZqpfsyHfc0
@xiaosage
@xiaosage 4 жыл бұрын
comprehensive and explicit explanation !
@ambientbackdrops9532
@ambientbackdrops9532 Ай бұрын
Thank you, you have a gift for teaching.
@unboundborders
@unboundborders 3 жыл бұрын
Hi Steve, For some reason I am having trouble just getting the page to run with lite-server. Do you have a tutorial that explains what commands you need to use to get a HTML page up and running? I checked the HTML playlist and the JavaScript from the Start Playlist and I didn't see how you are launching the page. Thank you!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Here is a video I did on VSCode tips - kzbin.info/www/bejne/fKm1c52dicyomtk It includes one discussing the Live Server extension. This is how I launch pages
@unboundborders
@unboundborders 3 жыл бұрын
Thanks!
@mkamalkayani
@mkamalkayani 6 жыл бұрын
Thanks. I really liked your way of explanation.
@seanduignan294
@seanduignan294 4 жыл бұрын
Just as ya think you know it all; you learn something new! Great vid!!!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
You got that right!
@jasbindarsingh1640
@jasbindarsingh1640 4 жыл бұрын
Hi steve, Can I bind fun2 'this' to 'a' context? bind inst working let a = { fun1: function(){ console.log(this); }, fun2: () => { console.log(this); } }
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Arrow functions will not let you change the binding
@jasbindarsingh1640
@jasbindarsingh1640 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 so is this a major disadvantage of using arrow functions
@chesterxp508
@chesterxp508 3 жыл бұрын
Another very cool tutorial !!!
@web-dev01
@web-dev01 6 жыл бұрын
thanks Steve for your great work
@sashaikevich
@sashaikevich 6 жыл бұрын
And at the end of the video, if you change line 10 to a normal function declaration, will the 'this' on line 11 refer to myFunc?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
It will be referring to the window/global object. setTimeout( function( ){ console.log(this); }, 1000); In this bit of code, the function is being called asynchronously. The regular, non-arrow, function does not care where it was declared it cares how it was called. In what context was it called? Global / window. Now consider this version: setTimeout( (function(){ console.log(this) }).bind( box ), 1000 ); Here, we are providing a context for the function. "box" is the "this" context. The console will log out the box.
@elminaiusifova4852
@elminaiusifova4852 6 жыл бұрын
You are passing the context with "call", can we pass the context without call? Ex: myFunc(box) or myFunc(window)? Will the function see the passing context this way?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
func.call( context ) and func.apply( context ) are the two ways to officially pass the context to the function. You can always pass any value to the function through a normal parameter. "the context" could be something that you are passing to the function to be used. HOWEVER, what you don't get is the ability to use the keyword "this" inside the function to refer to that context.
@elminaiusifova4852
@elminaiusifova4852 6 жыл бұрын
Will THIS in arrow function always point to the global context? Are there any cases where it will point to the Who called this function ? What if that arrow function is super nested?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
Arrow functions will always use the lexical scope. The scope of their surrounds, where the function was written. gist.github.com/prof3ssorSt3v3/a42ee8ba1cad64e08a503df43a4a8dc0 This GIST has an object with a bunch of methods being called with functions, arrow functions, and es6 shorthand method syntax. Then I am using a forEach loop to call an inner function to show were `this` points to the obj or to the global/window object. try running it either in the browser console or in the terminal with NodeJS to see the differences in action.
@zunairullah
@zunairullah Жыл бұрын
Einstein said If you can't explain it simply, you don't understand it well enough. This keyword is not hard but it is the poor teaching skills of people who claim they know it but they dont even know it really. I ve gone through many tutorials but no one is able to explain as steve did it in a very simple, to the point and concise way
@howydasayed470
@howydasayed470 5 жыл бұрын
thanks , great video as usual !
@ocxigin9220
@ocxigin9220 3 жыл бұрын
Good job
@maitran1764
@maitran1764 4 жыл бұрын
I ran the following example codes from the MDN and everything worked fine: var obj = {a: 'Custom'}; var a = 'Global'; function whatsThis() { return this.a; } whatsThis(); // 'Global' whatsThis.call(obj); //'Custom' But when I change var a = 'Global' to let a = 'Global', whatsThis() becomes undefined in the console. Does changing var into let somehow affect the function's ability to access global variables?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
The difference is that var not only creates a variable it also adds a property of the same name to the window/global object. So var a is also creating window.a.
@maitran1764
@maitran1764 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Oh I see. Thank you very much!
@Red00022
@Red00022 Жыл бұрын
This is a bit like classes and subclasses
What is AJAX and Why Should I Care
7:59
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 27 М.
What the lexical is this?
33:01
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 5 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Understanding Passing by Reference or Value in JavaScript
13:17
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 7 М.
JS Function Methods call( ), apply( ), and bind( )
13:14
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 38 М.
Arrow Functions JavaScript Tutorial - What NOT to do!!!
31:48
ColorCode
Рет қаралды 61 М.
Visually Understanding JavaScript Prototypes
14:58
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 55 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,3 МЛН
Using JavaScript Strict Mode
13:04
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 6 М.
ES6 Iterator & Generator Fundamentals
18:18
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 31 М.
What is THIS keyword in JavaScript? - Tutorial for beginners
26:40
Reference Vs Value In JavaScript
15:12
Web Dev Simplified
Рет қаралды 186 М.
JavaScript Classes vs Prototypes
14:39
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 63 М.