Check out a free preview of the full Advanced JS Fundamentals to jQuery & Pure DOM Scripting course:
The "Exercise 7: Implementing $.isArray()" Lesson is part of the full, Advanced JS Fundamentals to jQuery & Pure DOM Scripting course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will implement your own $.isArray() method for type checking Arrays. Justin also reviews how to use the toString() method for type checking.

Get Unlimited Access Now

Transcript from the "Exercise 7: Implementing $.isArray()" Lesson

[00:00:00]
>> [MUSIC]

[00:00:02]
>> Justin Meyer: So here's the exercise, so we're gonna do this first. If the method, did I show the method? The hint is using Object.prototype.toString.call. If that seems a little weird, the reason why we have people go through this exercise is because we will be stealing. This is kind of like this is, I forget the name for this, the objects that are kind of part of JavaScript.

[00:00:30] So we're gonna be stealing array's methods, we'll be using them for own devices. Here we're using an Objects toString method for own devices on other objects. What is the word? Mark, help me out.
>> Speaker 2: [INAUDIBLE]
>> Justin Meyer: I've totally forgotten what's the word for that is.
>> Speaker 2: [INAUDIBLE]
>> Justin Meyer: It's a phrase for like what it is called, it's not like, yeah, I don't remember it.

[00:00:53] Okay, I'll look it up, it's like drawing a blank. But we do this stuff a lot, a lot of libraries do this stuff where they'll steal.
>> Speaker 2: More.
>> Justin Meyer: It's when you like use place but I'm your own like or a like array or object but it's not do you mean like J Crew does it all over the place to get the name of it though it's like not.

[00:01:18] It's kind of like a duck punching but it's something that's there's another term of phrase that it's called, I forgot it's called. I have to remember it, this is kind of a common pattern of stealing these type of methods but using them on your own type of objects.

[00:01:37] So you wanna introduce it at your simple, so it kind of you're used to it later. So any questions about this exercise before we start?
>> Justin Meyer: No, all right, so just to recap, it's weird to think about, but it's more simple than you might think. You're really just using this object prototype toString.call method and making sure that it returns object Array and as long as it does then you know it's an Array.

[00:02:15] And you will be implementing that in here, so that's your object and you just want this to return true or false.
>> Speaker 2: [COUGH]
>> Justin Meyer: If this thing is truly an Array.