From the course: Learning CoffeeScript

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using aliases for "this" and other tidbits

Using aliases for "this" and other tidbits - CoffeeScript Tutorial

From the course: Learning CoffeeScript

Start my 1-month free trial

Using aliases for "this" and other tidbits

Now cofeescript has a lot of other different ways that it tries to help you. So I'm going to talk about some of these in here. One of them is that it provides you with an alias for an argument called this. and it's pretty awesome. So let me explain about this a little bit. When a function is invoked, it gets two special parameters assigned to it. You may already know that functions come with an arguments parameter. That argument allows you to list all the items that were passed to the function, and it could be pretty useful. Well, in addition to that, every function also gets a this argument, and it's supposed to let you access the current object. Normally, you would expect This to refer to the function that you're using. But in a lot of instances, it returns the wrong thing. So, it really makes more sense if I show it to you. Let go ahead and create a new function here. We'll call it fill and it'll take item. And we'll use a CoffeeScript arrow to execute this function. I'm going to…

Contents