YDKNJS this object prototypes Flashcards
how to reference a function inside itself?
by using it’s name
can you reference an anonymous function inside itself?
no because it has no name
is ‘this’ compile time binding or runtime binding?
runtime binding
how is ‘this’ determined?
by how the function was called not where was it declared
what are the rules of binding?
1 - default binding -> global object
2 - implicit binding -> obj.fn
3 - explicit binding -> fn.call(obj) or .apply(obj)
4 - hard binding -> wrapping around the fn.call() another function so that it never loses it’s ‘this’binding ex:fn.bind()
5 - new binding -> new foo();
how can u always maintain an object binding to a function?
using fn.bind(obj)
how does the ‘new’ differ in js?
t’s not creating a new instance but just invoking a function that happens to be called a constructor
what is the order of precedence in ‘this’ binding?
1 - new binding
2 - hard binding or explicit binding
3 - implicit binding
4 - default binding
what is the ‘this’ binding for .call(null)
default binding
what is the ‘this’ binding of arrow functions?
it binds to the lexical scope of the this of the outer function it’s enclosed in
what happens to default binding using strict mode?
this becomes undefined