DEV Community

Cover image for You don't know JS: Summary - Chapter 1 and Chapter 2 (this and Prototype)
Jasneet Sawhney
Jasneet Sawhney

Posted on

You don't know JS: Summary - Chapter 1 and Chapter 2 (this and Prototype)

  1. The best approach to avoid the use of anonymous functions altogether requires a self-reference, and instead uses a named function.

  2. using call(..), we ensure the "this" points at the function object itself.

  3. Internally scope is like an object with properties for each of the available identifiers. but the scope "object" is not accessible to javascript code. It's an inner part of the engine's implementation.

  4. "this" is not an author time-binding but a run time-binding.

  5. When a function is executed, a context is created known as execution context.

  6. "this" is a binding made for each function invocation, based entirely on its call-site.

  7. Boxing - If you pass a simple primitive value (boolean, num, or string) as "this" binding, the primitive value is wrapped in its object form.

  8. A constructor in JavaScript is just a regular function that happens to be called with a new operator.

  9. Four rules of determining "this"
    • If the function is called with "new", then it's a new binding.
    • function called withcall or apply and encoded in hard binding, then it is an explicit binding.
    • function with a context object will fall under the implicit binding category
    • Otherwise, default binding.

  10. Arrow functions do not use these rules, these are the functions that use the "fat-arrow" operator "=>". The lexical binding of an arrow function can not be overridden.

  11. If you pass null or undefined as a parameter to call or apply or bind, then those values are ignored, and instead default binding rule applies. This is only done when you want to spread an array to be passed as arguments to functions. Though this can cause side effects, hence we use a DMZ(demilitarized zone) object, which is represented by ø (phi) stating the null, but in a better way.

$ var ø = Object.create(null)
$ foo.apply(ø, [2,3])
~~~

--------------------------------------------------------------
If you want similar content, then visit https://iaminnovativecoder.com

Follow me on : 
YouTube - https://youtube.com/InnovativeCoder
Instagram - https://instagram.com/innovative_coder
Enter fullscreen mode Exit fullscreen mode

Top comments (0)