Skip to content

Instantly share code, notes, and snippets.

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

JavaScript Functions

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

  • Function expressions store them in variables. Function declarations start with "function [name]" and are hoisted.

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

  • Should refer to the function in the context it's being run in. This is the window "normally".

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

  • It should refer to the object based on the context it was called from.

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

  • Can be controlled with .call() or .apply() for example. These allow you to pass the value of 'this' as a first argument.

I can explain the difference between call and apply.

  • Apply takes the arguments as an array.

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

  • Asynchronous cases where we want to call the function later.

I can explain how bind works.

  • Bind is similar to apply but sets 'this' when the function is defined, rather than when it's called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment