Skip to content

Instantly share code, notes, and snippets.

@jecrockett
Forked from stevekinney/1510-function-cfus.md
Last active March 30, 2016 17:33
Show Gist options
  • Save jecrockett/4da4b37c284becd1749bb85bb0a373a1 to your computer and use it in GitHub Desktop.
Save jecrockett/4da4b37c284becd1749bb85bb0a373a1 to your computer and use it in GitHub Desktop.

JavaScript Functions

I can explain the difference between function declarations and function expressions.

  • Well, at least one of them. Function declarations are hoisted, but with variables only the declaration (NOT the definition) is hoisted, so the variable still isn't defined until the code gets there.

I can explain what the value of this is in a normal function.

  • global object

I can explain what the value of this is when called from the context of an object.

  • it's the object.

I can explain how to explicitly set the value of this in a function.

  • i can pass the object in with call, apply, or bind.

I can explain the difference between call and apply.

  • call's first argument is this and the rest are passed in individually. Apply's first argument is also this, but the rest of the arguments are passed in in an array.

I can describe an case where I might need to use bind to avoid polluting the global scope.

  • Asyncronous things where a function might be called later, but not right in this moment. But, when it is called, we want the value of 'this' to be the same as it is right in this moment.

I can explain how bind works.

  • It basically creates a new functon where 'this' is defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment