Function Context Cheatsheet
Types of Invocation
Applies to only named and unnamed functions
Doesn't matter for fat arrow functions
Function-style invocation
Context of the function will be global context UNLESS binded
Method-style invocation
Context of the function will be the object which the function is called on UNLESS binded
Types of Functions
Named Function
explicit
return
keyword requiredcurly braces
{}
around function bodyNOT saved to a variable
parameters must be surrounded by parentheses
()
context is defined by how it's invoked or called
function-style: global context
method-style: context is object that function is being called on
calling
bind
on the function will return a function binded to the context of thebind
argument
Unnamed Function
explicit
return
keyword requiredcurly braces
{}
around function bodyMUST be saved to a variable
parameters must be surrounded by parentheses
()
context is defined by how it's invoked or called
function-style: global context
method-style: context is object that function is being called on
calling
bind
on the function will return a function binded to the context of thebind
argument
Explicit Fat Arrow Function
explicit
return
keyword requiredcurly braces
{}
around function bodyMUST be saved to a variable
parameters must be surrounded by parentheses
()
IF more than one parametertakes the context of where it's defined
CANNOT be binded using
bind
Implicit Fat Arrow Function
NO
return
keywordfunction body can only consist of what is being returned
Optional parentheses
()
around function body
NOTE: Parentheses needs to be used if returning an object
ex: ({ key: value })
MUST be saved to a variable
parameters must be surrounded by parentheses
()
IF more than one parametertakes the context of where it's defined
CANNOT be binded using
bind
Bind
bind
accepts multiple argumentsfirst argument is the context that you want to bind the function to
any arguments that come afterwards will be passed in when the bound function is called BEFORE the call time arguments
Last updated