techsflow.blogg.se

You dont know js confusing
You dont know js confusing









you dont know js confusing

I didn’t know that ES6 introduced a for of loop! It can be used to iterate over the values in an array. If you’re interested, see the ‘depending on circumstances’ link above for more detail on setting property values in chapter 5 of the book. This scenario happens when a setter is found on an object higher up the chain and has the same name as the specified property. No value will be added to the specified object and the setter definition will not change. This scenario happens when a property with the same name is found higher up the prototype chain but has writable set to false. No property will be added and the value won’t be set at all.This scenario happens when a property with the same name exists higher up the prototype chain and has writable set to true. This means a property with the same name would exist at two or more places in the prototype chain. Be added to the specified object, resulting in a “shadowed property”.If the property is found somewhere higher up the chain - depending on circumstances - it will either: If a property with the same name is not found anywhere in the chain, it will be added directly to the specified object with the specified value.

you dont know js confusing

If the property is not already present on the specified object, it will traverse the prototype chain (all objects linked to this one). If writable is not false, it will set the value of the property as usual. If writable is false, it will either fail (in non-strict mode) or throw an error (in strict mode), because the value cannot be changed. Second, it will check whether the property is a “data descriptor”, meaning it has only the default getter and setter definitions, and whether it has writable set to false. If the property is already present on the specified object, the put operation will start by checking two things:įirst, it will check whether the property is an “accessor descriptor”, meaning it has its own getter / setter definition (the default get and put operations can be be overridden with getters and setters). If it doesn’t find it, it will traverse the prototype chain (all objects linked to this one) until it either finds a property with the requested name and returns its value, or can’t find a property and returns undefined. If it finds it, it will return the value. Get first inspects the object for the property with the requested name. Wednesday September 6 | 8:30am Get and Putĭid you know that when you call obj.a to access the property a, what is actually being performed is a get() operation on the object? Similarly, when you add a property to an object obj.b = 2 a put() operation is performed.

  • If a function is called on its own, foo(), this will be either undefined (if in strict mode) or the global object (if in non-strict mode).
  • If a function is called on an objet, obj.foo(), this will be the object it was called on.
  • bind(), this will be the object that is passed in

    you dont know js confusing

  • If a function is called with the new keyword, this will be the resulting object.
  • If you’re at all fuzzy on this in JavaScript, I’d recommend reading the chapter.

    You dont know js confusing code#

    The book defines this as “a binding made for each function invocation based entirely on its call-site… the location in code where a function is called (not where it’s declared)”.Īt the end of chapter 2 the book gives a really great summary of the four rules that can be applied to determine this based on a function’s call-site. Tuesday August 29| 8:45 pm This, the call-site and the call-stack For more context, check out my earlier post.

    you dont know js confusing

    I’m blogging my learnings from the third book, this & Object Prototypes, here. I thought I’d do so by reading the You Don’t Know JS (YDKJS) book series. TLDR: I’m trying to gain a deeper understanding of JavaScript.











    You dont know js confusing