Skip to content

Instantly share code, notes, and snippets.

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

JavaScript Functions

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

  • Yes and, Function declaration has a name....where as a function expression is saved as a variable. Function declarations are hoisted, and expressions are not....the variables that are storing the functions are hoisted, but they are undefined until the variable is actually defined.

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

  • It is the global object.

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

  • It is whatever object its being called from.

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

  • use call. Only use it to explicitly set this....when passing in other arguments.
  • use apply. Only use it to explicitly set this....when passing in other arguments when they are in an array.
  • this hurts my brain

I can explain the difference between call and apply.

  • Yes, see above.

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

  • Sortof(ish)
  • We don't want to actually call that function just yet (asynch stuff happening), but we do want to explicitly set this.

I can explain how bind works.

  • Meh - Creates a new function where this has already been set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment