public and private
First look into a basic OOP concept that enables us to set the visibility of our methods and properties.
Video Transcript
00:00Now, the second thing that I wanted to notice is, well, I said the on timer is private,
00:04right?
00:05Because the on timer is a private function.
00:08How is it that a private function is accessible to my timer?
00:14That's a really big question.
00:15How is that?
00:16Because we're adding an event listener on timer.
00:18What is actually happening here?
00:19We are actually sending our on timer into the timer.
00:24And what it basically is, is we're basically sending the function.
00:26And when we're sending the function, we're basically releasing the rights of that function
00:31to be private.
00:32That stays inside of our on timer, inside of our class.
00:36It's still true that our timeout dot on timer, there's no one could get access to it.
00:42But if we decide that we're going to send that function outwards, then that function
00:46will have access to wherever it wants it, right?
00:48So we're just basically, we're passing the function away, just as if it was a variable.
00:55Just a side note, functions are a very smart variable in a way.
00:59And we're going to look into that at some point.
01:01But basically, a function is also, there's a type which is called function.
01:05So if we wanted to, we could have created a new variable here.
01:09And we could call it fun, which is a function, and we could say on timer.
01:13And on timer now, without setting the open and close bracket, we just pass the information
01:19of on timer, we pass the reference on timer to fun.
01:24If we wanted to, we then could pass fun, it doesn't really matter because all we're actually
01:27sending is a reference to that function.
01:30Just as much as if you're sending objects or stuff that are not primitive, you're not
01:34really sending the object itself, you're sending a reference to that object.
01:40And the same deal goes with functions.
01:42All right, so we got one more thing out of our belt.
01:47And don't worry about the function bar, that was just like an extra bonus if that
01:50sounded interesting.
01:51And if not, you could forget about it for now.
01:53It's not critical, and we might revisit it at a later point when we see it's more useful.
