What does fn.call do and how do you use it? What impact does it have on
this?
Rewrite this code to make use of this instead of taking an argument:
function addFive(i) {
return i + 5;
}
console.log(addFive(10));
this inside of a function does not (necessarily) refer to the function
itself. How can you refer to the properties of a function from within that
function?
How does this relate to the "lexical scope" covered in the previous lesson?
Summarize the rules that determine the value of this.
Describe some situations where this can lose its value or have its value
changed.
How can you force this to a given value?
How are constructors in JavaScript different than in many other languages? How
does this impact this?
What are the six built-in types in JavaScript? Briefly describe each.
What are the difference between primitive types and object types in
JavaScript?
What is the value of "Hello string" instanceof String? Why?
What is the difference between using . to access a property and []? What
is a situation where you would use one over the other?
What is the difference between a "deep" copy and a "shallow" copy? How can you
get a shallow copy of an object in JS? What about a deep copy?
What are "getters"? How do you define one?
What are "setters"? How can you define one?
How would you describe the difference between a class and an instance of the
class? Conceptually, how do class systems take a class and make an instance of
that class?
Discuss how classes in JavaScript relate to classes in other languages (for
example, Java or C++).
Describe polymorphism and how it is used in object oriented programming.
What is the prototype chain? How is the prototype chain used when accessing a
property like example.foo?
Explain how Fn.prototype is used when calling new Fn().
What does instanceof actually do?
What is delegation and why is delegation important in JavaScript?
What are some advantages of ES6 class over using older ways of expressing
the OOP pattern in JS?
Note: Kyle Simpson pushes the OLOO pattern over OOP hard in this book, but we're
in that delusional group that speaks OOP in JS. We make heavy use of ES6
classes. It is absolutely useful to know what JS is actually doing and not
pretend like JS classes are like classes in other languages. However, we
think the language and syntax of classes and OOP is a very useful abstraction
for discussing design problems and expressing things in code.
Basically all frameworks and existing client code you will encounter are
expressed in OOP-like ways. React for example, draws a distinction between
component classes and elements (instances). You won't see much OLOO code out
there-- and won't see us make heavy use of that pattern.
The examples Kyle gives of the problems with ES6 "classes" are useful for
illustrating that nothing has really changed-- JS is still doing the same thing
under the hood-- but he's got to contort pretty hard to expose the issues with
the syntax. You just won't see much code like that in the wild (e.g. mixing
prototype style with ES6 classes, or dynamically re-writing class definitions
all over the place). And yeah, it is useful to pretend class syntax makes static
classes definitions-- it is a useful signal to yourself and other programmers
not to monkey with that particular object!
Read: https://github.com/getify/You-Dont-Know-JS/blob/master/this%20&%20object%20prototypes/README.md
Questions:
fn.call
do and how do you use it? What impact does it have onthis
?this
instead of taking an argument:this
inside of a function does not (necessarily) refer to the function itself. How can you refer to the properties of a function from within that function?this
relate to the "lexical scope" covered in the previous lesson?this
.this
can lose its value or have its value changed.this
to a given value?this
?"Hello string" instanceof String
? Why?.
to access a property and[]
? What is a situation where you would use one over the other?example.foo
?Fn.prototype
is used when callingnew Fn()
.instanceof
actually do?class
over using older ways of expressing the OOP pattern in JS?Note: Kyle Simpson pushes the OLOO pattern over OOP hard in this book, but we're in that delusional group that speaks OOP in JS. We make heavy use of ES6 classes. It is absolutely useful to know what JS is actually doing and not pretend like JS classes are like classes in other languages. However, we think the language and syntax of classes and OOP is a very useful abstraction for discussing design problems and expressing things in code.
Basically all frameworks and existing client code you will encounter are expressed in OOP-like ways. React for example, draws a distinction between component classes and elements (instances). You won't see much OLOO code out there-- and won't see us make heavy use of that pattern.
The examples Kyle gives of the problems with ES6 "classes" are useful for illustrating that nothing has really changed-- JS is still doing the same thing under the hood-- but he's got to contort pretty hard to expose the issues with the syntax. You just won't see much code like that in the wild (e.g. mixing prototype style with ES6 classes, or dynamically re-writing class definitions all over the place). And yeah, it is useful to pretend class syntax makes static classes definitions-- it is a useful signal to yourself and other programmers not to monkey with that particular object!