02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

The is Operator

The is operator enables us to check and see if an object is a Object type. Learn how the is operator works and how we can use it to check to see if one of our object is a type of class.

Video Transcript

00:01So let's look into it.
00:02So let's open up our main class.
00:04And when we open up our main class,
00:05things are going to start falling in place.
00:08So first of all, I'm going to open up our main class.
00:10And our main class is open.
00:12We already have here an onClick that's sitting here and waiting,
00:15even though we didn't create any clicks yet.
00:17And we have an onTouch, which we could delete.
00:19Because for our sake of example, we
00:23don't care about the event of onTouch that gets triggered.
00:26But we'll leave it there for now.
00:27All right, so our first step that I want to do
00:29is I want to go to the animal classes,
00:31and I want to remove that click event.
00:34I want to go to our cup of water.
00:35And again, in our cup of water, find our click event,
00:38remove the click event.
00:39If I'm ready here, let me also delete that trace.
00:42So now we have our animals, and we have our cup of water.
00:45And if we run our application, nothing
00:47will happen when we click on either of them.
00:51All right, so our next step is really,
00:52we want to expose our clicks and have them happen
00:55externally from our main class directly.
00:57Now, one thing that we could do directly in our main class
01:00is we could just add a new event directly to our main.
01:03So I could send here this.addEventListener.
01:07And really, it's the exact same code.
01:09So I rewrite everything, right?
01:10So I'm going to copy our addEventListener.
01:13And it could be right here in our main.
01:15We already have an imported mouse event.
01:16We have an onClick.
01:18We can even see what is being clicked.
01:20So if we click on the water, we
01:22should see that our cup of water was clicked.
01:24If we click on our dog, we could see that our dog was
01:26clicked.
01:27If we click on our cat, we could see our cat was clicked.
01:29Only problem is, is if we click on our fire,
01:32our fire gets clicked.
01:33And if we click on our logo, our logo gets clicked.
01:36And if we click on our polychromism and interfaces,
01:40that is clicked as well.
01:41But we need to know a way, and we
01:42need to have a way to differentiate and actually
01:45know what was being clicked.
01:47Now, previously, we had a way of doing it
01:49because we were only approaching our animals.
01:51And we could have just gone to our animals
01:53and just asked if our e.target is a type of animal.
02:00So let's import that for a second.
02:01Let's import our flash.op.
02:04Not flash.com.02.
02:11geek.op.inheritance.animal.
02:17And we could have asked if it is animal.
02:20I'm just going to trace this out for a second,
02:22just so you could see if anything is an animal.
02:26A very simple syntax.
02:27We take on one side what we're actually talking about,
02:29and then we ask if it's a type of whatever that is.
02:32If it is that, basically, we're asking, is it that?
02:35And if we ask fire, is it that?
02:37No, it's not that.
02:38If we ask water, is it an animal?
02:40It's not an animal.
02:41If we ask a dog if it's an animal, it definitely is.
02:44And if we ask a cat if it's an animal,
02:46it surely is an animal.
02:47So now we have a way to differentiate,
02:49and we know how to target our cat and our dog.
02:51But still, we have no way to treat the cat, the dog,
02:54and the water as one until we meet interfaces.
02:59So we know that we have this capability of asking something
03:02if it is that.
03:03Our next step is to create an interface,
03:05and this is exactly where interfaces come to play.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!