<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrew Hrushetskyi</title>
    <description>The latest articles on DEV Community by Andrew Hrushetskyi (@andrii256).</description>
    <link>https://dev.to/andrii256</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F555625%2Fbf6b20b2-f3e6-42f8-b7a0-05ce063cee59.jpg</url>
      <title>DEV Community: Andrew Hrushetskyi</title>
      <link>https://dev.to/andrii256</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andrii256"/>
    <language>en</language>
    <item>
      <title>Feel Behind on Skills, Hooks, Agents and Others? The Mental Model That Explains It All</title>
      <dc:creator>Andrew Hrushetskyi</dc:creator>
      <pubDate>Tue, 02 Jun 2026 16:51:25 +0000</pubDate>
      <link>https://dev.to/andrii256/what-your-claude-code-is-really-capable-of-narrative-explanation-4akj</link>
      <guid>https://dev.to/andrii256/what-your-claude-code-is-really-capable-of-narrative-explanation-4akj</guid>
      <description>&lt;p&gt;You're on your usual route through the Zone.&lt;/p&gt;

&lt;p&gt;Same broken road, same dead trees, same nothing.&lt;br&gt;
The wind drags through the dead branches. Your boots squelch in the wet gravel. Somewhere far off something creaks and you don't even bother turning your head.&lt;br&gt;
The Geiger counter ticks along, slow and lazy. Nothing dangerous. Just background.&lt;br&gt;
You're half bored, half on edge. That's the Zone for you - you stop feeling the fear, but it never actually goes anywhere.&lt;br&gt;
You're cold. You just want to be home already.&lt;/p&gt;

&lt;p&gt;And then you see, far off, something moving in the fog!&lt;br&gt;
You raise your rifle, get ready to shoot. And suddenly you hear:&lt;/p&gt;

&lt;p&gt;-- Don't shoot! We are not mutants!&lt;br&gt;
-- (another voice): Listen! My name is Opus. Here are my friends: Sonnet and Haiku. We are reptiloids and we flew here from the planet Nibiru to study your planet. We have no ill intentions and pose no threat to you. Please, let us go.&lt;br&gt;
-- (the last voice): Here, I've got an intergalactic modem, I'm giving it to you (puts it on the ground). You can write us any letters anytime. We're very well-read and we know a lot. Just please don't shoot!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3l1d4y4cywaxsczkh7a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3l1d4y4cywaxsczkh7a.png" alt="Stalker looks onto reptiloids" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You're standing there dumbfounded.&lt;br&gt;
The rifle's still trained on them, but you have no idea what to say back, so you just nod. They start backing away quietly and after a couple of minutes they vanish somewhere into the fog.&lt;/p&gt;

&lt;p&gt;You walk over to where they were standing and grab their modem.&lt;/p&gt;



&lt;p&gt;And a few days later, once you've finally made it out of the Zone, you start checking out their miracle modem.&lt;/p&gt;

&lt;p&gt;And as you test out this new gadget (that is, send your reptiloid friends intergalactic emails), you discover a few properties of these reptiloids:&lt;/p&gt;


&lt;div class="crayons-card c-embed"&gt;

  These reptiloids are very, very well-read. They've read and listened to the works of all of humanity's philosophers, the speeches of Hitler, Putin Trump, Zelensky, and even the Lion King from the cartoon of the same name. These reptiloids have watched every episode of anime, all the Epstein files, all of reddit. They are incredibly well-read.
&lt;/div&gt;



&lt;div class="crayons-card c-embed"&gt;

  But! At the same time, when you write them an email like "remember last week I wrote you about ...", they can't recall it. It just so happened that they remember the whole internet, but your conversations with them they don't memorize and don't remember. And every time you send some email, you have to, within that same email, resend the entire history of the correspondence with all the attachments every single time. The whole context all over again, every time.
&lt;/div&gt;


&lt;p&gt;And of course it's terribly boring to manually copy the previous conversations by hand every single time.&lt;/p&gt;

&lt;p&gt;This is routine nonsense that can and should be automated. So you decided to write a middleman program (an agent), which at the bottom will have a text input, and will keep your conversation history in memory. And you'll just type something of your own into the text input, and the program will take what you wrote, pull the history of your correspondence out of memory, glue your short prompt and the whole conversation history into one big prompt and send the reptiloid this big prompt. And when it sends back a reply - display it nicely as a chat and save its reply into memory. And so on, round and round.&lt;/p&gt;

&lt;p&gt;Congrats. You've just invented the browser-based ChatGPT of 2022.&lt;/p&gt;

&lt;h2&gt;
  
  
  The key to everything that follows: LLMs are stateless!
&lt;/h2&gt;

&lt;p&gt;LLMs are stateless. Somewhere inside themselves they remember the entire internet in the form it was in at the moment of their training, but they don't remember your correspondence with them. You have to send them everything all over again every time.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every time you send a message, it's the sending of a completely new message, just with the conversation history attached.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what it would look like if your middleman program didn't save the chat history and didn't resend it from scratch each time:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrjpp6rh4qcpx9upsid6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrjpp6rh4qcpx9upsid6.png" alt=" " width="660" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's try to guess what the regional office employee is going to ask =)&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools
&lt;/h2&gt;

&lt;p&gt;Life was getting better and better and more and more interesting. The reptiloids replied incredibly fast and helped find answers to many questions. Thanks to your primitive agent (the middleman program), which was more like a chat, communicating with the reptiloids was incredibly convenient.&lt;/p&gt;

&lt;p&gt;But at some point you wanted more: you wanted the reptiloids to write code instead of you.&lt;/p&gt;

&lt;p&gt;At first you started by writing to the reptiloids what code you wanted them to write. They'd ask you to send a couple of files for context. You'd send it to them, manually. Then they'd send you that code. And you'd go and paste that code into the file manually. And at some point this got boring too, and you wanted to go even further - to automate even this ctrl+c + ctrl+v.&lt;/p&gt;

&lt;p&gt;So you improved your middleman program and it started working as follows:&lt;br&gt;&lt;br&gt;
When you type some text into the text field and press enter - your program takes your text, and to this text it adds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dear Opus. To make it easier for you to do this task, you have a few options. You can use any of them:

- Read. If you need to read the contents of some file - send me the keyword «!_&amp;amp;Read&amp;amp;_!» and along with it the path to the file you want to read.
- Write. If you want to write something into one of the files - send me the keyword «!_&amp;amp;Write&amp;amp;_!» and along with it the line to append to, and the content to append.
- Grep. If you want to perform a search through the file system - send me the keyword «!_&amp;amp;Grep&amp;amp;_!» and along with it the pattern to search by.
- Fetch. If you want to get the contents of some web page of our earthly clunky internet - send me the keyword «!_&amp;amp;Fetch&amp;amp;_!» and a url address.
- .... and many others.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then your agent glues together your prompt that you typed into the text field + the conversation history + a description of the available Tools like in the example above. And it sends this whole solid prompt to the reptiloid.&lt;br&gt;&lt;br&gt;
The reptiloid reads all of this. If the information you provided is enough for it, then it sends back &lt;code&gt;«!_&amp;amp;Write_! ./index.ts line:23 Content: const abracadabra...»&lt;/code&gt;. Your agent, that is, your program, parses this reply, pulls the arguments out of this reply, and simply does the work on the file system.&lt;br&gt;&lt;br&gt;
If the reptiloid decides that the information given to it isn't enough, then it sends the keyword for Grep, your middleman program parses the reply, and performs the Grep, and then takes the results of that search, adds them to all and conversation history to new prompt, and resends all of this as a new email/request to the reptiloid.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Reptiloids (LLMs) live on Nibiru, they don't have direct access to your computer, to its file system, or to google, or to anything else. Reptiloids can only receive messages and reply to messages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But your middleman program automatically builds a big prompt with all the details, it's your middleman program that pastes into your prompt the description of the Tools it can provide to the reptiloid. Then the reptiloid sends an order to your middleman program in a special format, and it's already your middleman program that performs the actions on the file system.&lt;/p&gt;

&lt;p&gt;Here's how Claude Code "reports" what it did according to the LLM's orders&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqy52u3khbi7zss04qgc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqy52u3khbi7zss04qgc.png" alt="Screenshot from claude code vscode extension" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here's how this can be represented schematically:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3dfneg2dnzdgfmv75ey.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3dfneg2dnzdgfmv75ey.png" alt="Basic schema of how claude code works" width="800" height="530"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Hooks
&lt;/h2&gt;

&lt;p&gt;With the invention of Tools, your life became much more convenient. Now you don't have to copy-paste everything manually. Your middleman program does it instead of you.&lt;/p&gt;

&lt;p&gt;But you still have to run the linter manually.&lt;br&gt;&lt;br&gt;
What's more, you'd like to restrict the reptiloid's ability to read the &lt;code&gt;.env&lt;/code&gt; file or run &lt;code&gt;git reset --hard &amp;amp; git push --force&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Of course you could hardcode such functionality right into the code of the agent itself. But in one project there's one situation, one set of needs, in another project there are others.&lt;/p&gt;

&lt;p&gt;So you decided to create hooks:&lt;br&gt;&lt;br&gt;
You extended your middleman program as follows:&lt;/p&gt;

&lt;p&gt;In your project. I emphasize, right in the code of your project, in a special file in a special little folder, you write down a list of hooks. In each hook you write&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the condition for when exactly this hook should intervene&lt;/li&gt;
&lt;li&gt;what needs to be done&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, to restrict access to the .env file you write a hook into that file, where you write:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the condition for when to intervene: before the Read tool is executed&lt;/li&gt;
&lt;li&gt;what needs to be done: check whether among the list of files for Read that the reptiloid sent there's a file named .env. If there isn't, then continue. Or if there is .env, then reject the execution of the tool.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And after this, every time the reptiloid sends a reply that contains an order to your agent, the agent, before executing Read, first runs your hook.&lt;/p&gt;

&lt;p&gt;To run the linter you add into that file, where you write:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the condition for when to intervene after the Write tool is executed&lt;/li&gt;
&lt;li&gt;what needs to be done: npm run lint&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I gave simple examples. But the whole point is that such an architecture of the agent allows you to configure the work of this agent very flexibly for each project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heads up!:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hooks are not something that goes as context to the LLM! Hooks are a condition and code that needs to be run when it's met, which the middleman program runs regardless of whatever the LLM said. Your middleman program executes your hooks without asking the LLM about it and executes them even if the LLM is somehow against it.&lt;/p&gt;

&lt;p&gt;Here's how this can be represented schematically:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fac5ty4r40njjhaazfgma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fac5ty4r40njjhaazfgma.png" alt="Schematical explanation how hooks in claude code work" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we take an analogy, you can imagine that writing a hook for claude code is like writing &lt;code&gt;document.addEventListener("the type of event for when to intervene", (event) =&amp;gt; what to do)&lt;/code&gt;. And if we take this analogy, inside the "what to do" you can write &lt;code&gt;event.preventDefault()&lt;/code&gt; (that is, abort the default execution).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heads up:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
I told only about two most commonly used hooks (PreToolUse (before the tool is executed) and PostToolUse (after the tool is executed)). But there are also Stop, Notification, SubagentStop and &lt;a href="https://code.claude.com/docs/en/hooks" rel="noopener noreferrer"&gt;others&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  MCP servers
&lt;/h2&gt;

&lt;p&gt;You got on a roll. And wanted even more. You wanted the middleman program not only to add the contents of files or make changes to those files according to the reptiloid's replies.&lt;br&gt;&lt;br&gt;
You wanted the middleman program to also send queries to the database according to the reptiloid's replies, or even interact with the browser according to the reptiloid's replies, or go grab information from Figma and add it to the context for the reptiloid according to the reptiloid's orders.&lt;/p&gt;

&lt;p&gt;And in general, in general, all of this could be done as a Tool. But this is all hardcode. And while in the case of Read/Write hardcode makes sense, because it's just basic functionality that's definitely needed everywhere. Then various additional tools - that's already something there can be a whole lot of, very different. And for one project it's this, for another project it's that.&lt;/p&gt;

&lt;p&gt;So you did it differently:&lt;/p&gt;

&lt;p&gt;First, from your mason friends you learned that they came up with a special MCP protocol for servers (special rules by which a server receives questions and sends replies. Much better adapted for the work of reptiloids than sending RestAPI request, for example).&lt;/p&gt;

&lt;p&gt;Second, you added to your middleman program the ability to work with such MCP servers from Figma, from Playwright, and from others.&lt;/p&gt;

&lt;p&gt;Now in the settings of each separate project you add only those MCP servers that are needed in this project.&lt;/p&gt;

&lt;p&gt;And then when you type something into the middleman program, it sends both your prompt, and the conversation history, and the list of basic tools, and additionally also the list of available MCP servers, and then the reptiloid, if it considers it necessary, sends an order to the agent to send a query to one of the MCP servers. The middleman program parses this reply, sends such a query to that MCP server, and adds its reply to the next prompt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Model Context Protocol? Why not another protocol?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because after meeting the reptiloid Opus you started researching the topic of reptiloids more seriously and started going to the masons' gatherings. And there you learned that besides Opus from Nibiru, there's also Codex from the planet OpenAI, DeepSeek from the planet Hammer&amp;amp;Sickle, Grok from the planet FromTheHeartToTheSun, and others. And it turned out that the other masons were too lazy to make a separate protocol (and therefore a separate server) for each separate reptiloid, so they agreed to use the same protocol regardless of which reptiloid they're friends with. And you thought, like, "well why not? I'll use it too."&lt;/p&gt;

&lt;p&gt;An important clarification: an MCP server is literally a server, it's not an abstraction. An MCP server can be run not only locally (like from playwright or from nextjs devtools), but also remotely: for example Figma, Github, Jira.&lt;/p&gt;
&lt;h2&gt;
  
  
  Subagents
&lt;/h2&gt;

&lt;p&gt;Everything is already very, very good. But there's a problem:&lt;/p&gt;

&lt;p&gt;The size of the message you can send the reptiloid at once is very big, but still limited.&lt;/p&gt;

&lt;p&gt;At some point the conversation history with all the contents of files, with the history of what was written where into which file, with the history of queries to MCP servers and their replies, all of this, all this conversation history with the reptiloid becomes so enormous that it simply doesn't fit into one message to the reptiloid.&lt;/p&gt;

&lt;p&gt;Worse than that. Even if the message size didn't exceed the limit - still, when it's too big - that's bad. The reptiloid, even though it's very powerful, is still an alien and even with well-picked context it might, instead of the expected result, send back some gibberish. And when that context is too tangled and contradictory, that is, when your agent crammed in everything - the risk of getting humanoid anime instead of js code in reply grows even stronger.&lt;/p&gt;

&lt;p&gt;And so it turns out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if the middleman program trims part of the conversation history, then context might get lost and the probability that the reptiloid sends gibberish grows&lt;/li&gt;
&lt;li&gt;if the middleman program doesn't trim part of the conversation history, but just crams everything in indiscriminately, the probability that the reptiloid sends, once again, gibberish, also grows. Worse than that, sooner or later the conversation history will become too big and the reptiloid will stop replying altogether&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What to do?&lt;/p&gt;

&lt;p&gt;One of the options is to launch a new instance of the middleman program, in which you again send the reptiloid the list of tools, the list of MCP servers and everything else, and the task that the reptiloid assigned to the middleman program in the first main chat (in the main instance, in the main session) to forward that task to the reptiloid in a new session. And after the new instance of the middleman program (that is, the subagent) finishes the correspondence with the reptiloid, that subagent returns the brief results to the main session, to the main correspondence.&lt;/p&gt;

&lt;p&gt;So that's what you did. You made it so that now your program, in addition to the information about the basic tools and the information about the MCP servers, also adds to your prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dear Opus! This is your friend Andrii!
As friends we must help one another.
So help me do this: ${promptFromUser}.
Remember that you can order me to perform one action or another, namely ${toolsWithGuide}.
Also remember that you can order me to send a query to an MCP server, namely ${mcpServersWithGuide}.

MOREOVER, dear friend Opus, if you think that none of the tools
or MCP servers I described above is enough to solve this problem, then describe in your own words what I should do and I will surely do it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But after Opus sends a task to you, to you specifically, your middleman program doesn't wait for you specifically to do that task. After Opus sends a task to you, to you specifically, your middleman program creates a new instance of itself (of the middleman program, that is, launches a subagent), and passes this task into that new instance (into that subagent) as a starting prompt. And then when that new instance finishes the correspondence with Opus where Opus solves its own task with the hands of your subagent, that new instance of the agent (the subagent) returns to the first correspondence only the result of solving that task (and not the whole conversation history). And your middleman program writes back to Opus:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dear Opus!
You and I were talking about:
${chatHistory}.

The task you assigned me, I diligently completed. Here's what came out of it ${answerFromSubagentChat}.
Taking this into account, please carry out the original task that I assigned you.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And although this sounds a bit cyberpunk, even a bit cheaty. But as we know, the reptiloid Opus doesn't remember previous conversations and clearer context is much better for him. Everything we want to tell it - we have to tell it in this one message. So this is also a fairly popular approach.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34i04cwjlwlef773qupw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34i04cwjlwlef773qupw.png" alt=" " width="799" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixed project information
&lt;/h2&gt;

&lt;p&gt;A very important part of the context is the explanation of who you are, what your project is about and what kind of answer you want.&lt;br&gt;
And so as not to copy this explanation manually every time, you decided to write it in &lt;code&gt;README.md&lt;/code&gt; and make it so that your middleman program inserts the contents of this &lt;code&gt;README.md&lt;/code&gt; into your message to the reptiloids every time.&lt;/p&gt;

&lt;p&gt;But then you realized that &lt;code&gt;README.md&lt;/code&gt; isn't quite convenient for this and that for the information you want to pass to the reptiloids it's better to use a different file with a different name. And so you decided to create &lt;code&gt;CLAUDE.md&lt;/code&gt; and reworked your middleman program so that in each correspondence with the reptiloid it inserts into that correspondence the contents of the &lt;code&gt;CLAUDE.md&lt;/code&gt; file, and not &lt;code&gt;README.md&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  On-demand knowledge loading (Skills)
&lt;/h2&gt;

&lt;p&gt;Time went on. The number of notes for the reptiloid in &lt;code&gt;CLAUDE.md&lt;/code&gt; kept growing. And at some point it became too enormous.&lt;/p&gt;

&lt;p&gt;So you decided to get around this in the following way:&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;CLAUDE.md&lt;/code&gt; you left only the most important information for the reptiloids. And everything else you cut out of there and split into many many smaller little markdown files. In each little file at the top you wrote a short name, a short description (max 1024 characters). And below - that very knowledge already in its full completeness.&lt;/p&gt;

&lt;p&gt;And you reworked your middleman program in the following way:&lt;br&gt;&lt;br&gt;
Your middleman program sends the reptiloid your prompt, the list of available tools, MCP servers, and also, also sends the list of those .md little files and says&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dear Opus. Here's the list of available knowledge:
${knowledges.list("name", "description") /* the content is not passed */}.
If you need any of it, then write me the keyphrase "I need the knowledge named ___"
and I'll send it to you.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When Opus decides that it needs one of those pieces of knowledge, then it sends the corresponding reply. Then your middleman program parses that reply, and goes to carry out the order - pulls out that little file, attaches it to the conversation history and resends it as a new letter to Opus. And it generates the next reply already taking into account that piece of knowledge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why are skills called skills, and not on-demand knowledge loading?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
I also agree that on-demand knowledge loading fits this feature much better.&lt;br&gt;
But if you tell investors: "We added to the middleman program the ability to split knowledge from one big file into many small ones and to send the LLM only the list of these files at the start so as not to overload the context. And we named this feature On-demand Knowledge Loading" - nobody will give you any money.&lt;br&gt;&lt;br&gt;
But the statement: "Our agents are now not just a mix of a constructor for building prompts and a parser that then performs one action or another. Our agents are now something new and incredible: they can have SKILLS. This is a new revolution! A new breakthrough! The world has changed irreversibly. We've overtaken our competitors threefold, gotten twice as close to inventing AGI, and we're about to take over the world. Bring the money while we're still taking it!" attracts investments much better. So it just historically worked out that they were named Skills after all, and not On-demand Knowledge Loading. Frankly, it's time to get used to the fact that in the 21st century the names for tools are given by marketers, not engineers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Commands
&lt;/h3&gt;

&lt;p&gt;In the process of using your toolset, you noticed that you write some prompts regularly. That there are situations when you write the very same thing every time. Only the argument changes (for example, the path to a file).&lt;/p&gt;

&lt;p&gt;At first, you kept a list of template prompts in a separate notebook and copied them manually whenever you needed one. Eventually that got tedious, so you built something better:&lt;/p&gt;

&lt;p&gt;Inside your project, you created a small &lt;code&gt;commands&lt;/code&gt; folder. Each template prompt got its own &lt;code&gt;.md&lt;/code&gt; file. Then you updated your middleman program to read that folder - so now, instead of copying anything, you can just type &lt;code&gt;/filename&lt;/code&gt; in the chat like a slash command, follow it with an argument, hit enter, and the agent automatically expands it into the full prompt text, as if you'd typed it yourself.&lt;/p&gt;

&lt;p&gt;Here, by the way, the name conveys the essence pretty well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remarks
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The material was written by a human. The reptiloids only helped with translation to English.&lt;/li&gt;
&lt;li&gt;For a clean conscience I have to clarify: in real life Opus, Sonnet and Haiku don't show up to people in the Zone, they live in data centers (and not on Nibiru) and receive from the agent the list of available &lt;code&gt;tools&lt;/code&gt; usually in JSON format and as a separate field in the payload according to a special syntax, and not that «!&amp;amp;Read&amp;amp;! inside the prompt like I gave as an example.&lt;/li&gt;
&lt;li&gt;Sorry if thumbnail looks too much crazy. I try to experiment.&lt;/li&gt;
&lt;li&gt;Despite all this development of middleman programs, LLMs have remained LLMs. And they still hallucinate. Even with a ton of settings, a ton of correctly picked contexts etc., they still hallucinate quite often. And they hallucinate very dangerously, because very plausibly (the mistakes look very similar to the truth and are very hard to tell apart). The author is merely reviewing the existing features and is not calling for YOLO-mode vibe-coding. Especially in production.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The End
&lt;/h2&gt;

&lt;p&gt;Let's sum up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LLMs are stateless - they don't remember your previous messages. The whole conversation history is resent every time by the middleman program (the agent).&lt;/li&gt;
&lt;li&gt;Tools are not magic: the agent describes to the LLM which "orders" it can send, the LLM sends them, and then the agent performs the real actions on the computer. And the agent is not some "smart" thing, but an ordinary program that, besides button presses, uses the LLM's orders as a trigger to perform actions.&lt;/li&gt;
&lt;li&gt;Hooks - a way to intervene the execution of a tool "before" or "after", to add your own logic (linter, access restrictions, etc.) or any other moment of lifecicle.&lt;/li&gt;
&lt;li&gt;MCP servers - servers that work according to a special standard, the Model Context Protocol, so as not to hardcode every integration into the agent itself.&lt;/li&gt;
&lt;li&gt;Subagents - these are sort of a "meta-tool". That is, when instead of Read, Write, or calling an MCP, the agent opens a new subagent, where it starts a correspondence with the LLM itself and after reaching result returns only short result, not all the history to keep context in main agent clean.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CLAUDE.md&lt;/code&gt; - a file with the fixed context of the project or folder, which the middleman program inserts into every prompt. Sort of an analog of &lt;code&gt;README.md&lt;/code&gt;, but for the LLM.&lt;/li&gt;
&lt;li&gt;Skills - On-demand knowledge loading - the same &lt;code&gt;CLAUDE.md&lt;/code&gt;, but cut into pieces that are loaded on demand.&lt;/li&gt;
&lt;li&gt;Commands - template prompts that are convenient to call via &lt;code&gt;/prompt-name&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;And, of course, be sure to leave a like and write in the comments&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;life hacks, best practices and other insights from your own masonic experience
&lt;/li&gt;
&lt;li&gt;criticism
&lt;/li&gt;
&lt;li&gt;and would you shot to reptiloids?&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>productivity</category>
    </item>
    <item>
      <title>"this" in JS is SIMPLE as a rock</title>
      <dc:creator>Andrew Hrushetskyi</dc:creator>
      <pubDate>Tue, 26 May 2026 14:17:36 +0000</pubDate>
      <link>https://dev.to/andrii256/this-in-js-is-simple-as-a-rock-2hdp</link>
      <guid>https://dev.to/andrii256/this-in-js-is-simple-as-a-rock-2hdp</guid>
      <description>&lt;p&gt;&lt;strong&gt;What if I tell you that &lt;code&gt;this&lt;/code&gt; in JS is simple?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What if I tell you that there is no magic and you can come up with it in a few minutes?&lt;/p&gt;

&lt;p&gt;What if I tell you that there are simple 5-step algorithms that will help you quickly and definitively solve any &lt;code&gt;this&lt;/code&gt;-related task in JS and feel confident when working with it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can’t believe it?&lt;/strong&gt; Look, here it is:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;this&lt;/code&gt; is an implicit parameter, not magic
&lt;/h2&gt;

&lt;p&gt;When you define a function, you define which parameters it must expect. You define explicit parameters. For example, explicit parameter &lt;code&gt;smth&lt;/code&gt; in &lt;code&gt;function logSmth(smth) {console.log(smth)}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; is very same to it, but it is an implicit parameter. It means that the engine passes it itself, even though you don’t declare it.&lt;/p&gt;

&lt;p&gt;In case with explicit parameters You decide what to pass, and in case with implicit parameters (including this) the &lt;strong&gt;Engine decides itself, ruling by its own rules STEP BY STEP&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the rules?
&lt;/h2&gt;

&lt;p&gt;To decide what to pass inside your function under this value JS engine uses 5 simple conditions, 5 simple questions, step by step:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Is the function an arrow function?
&lt;/h3&gt;

&lt;p&gt;If your function is arrow one, then the engine does not pass this at all, and when you try to access this from within an arrow function, then the engine looks for it through closure, same as any other variable.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variableOutsideArrowFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;67&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variableOutsideArrowFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variableOutsideArrowFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// exactly same as on line 3&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// exactly same as on line 3&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nf"&gt;arrowFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to access this from within an arrow function, then it does not matter whether it is called as a method, whether strict mode is enabled, or even if the function was modified by .bind. If you try to access this from within an arrow function, then the engine will always look for it through the function’s closure, same as a plain variable. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5kgf7obejugpxdzx65b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5kgf7obejugpxdzx65b4.png" alt="step-1-is-function-an-arrow-function" width="792" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Was the function modified by &lt;code&gt;.bind&lt;/code&gt;, &lt;code&gt;.call&lt;/code&gt;, or &lt;code&gt;.apply&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;You can’t explicitly specify the value of this during the creation of the function. But you can create a new, modified one using &lt;code&gt;.bind&lt;/code&gt; with an explicitly specified value of &lt;code&gt;this&lt;/code&gt;, or you can call a function using &lt;code&gt;.call&lt;/code&gt; or &lt;code&gt;.apply&lt;/code&gt;, also explicitly specifying what to use as &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So if you try to access &lt;code&gt;this&lt;/code&gt; from within a normal (not arrow) function and you modified it by &lt;code&gt;.bind&lt;/code&gt; , &lt;code&gt;.call&lt;/code&gt;, or &lt;code&gt;.apply&lt;/code&gt;, then &lt;code&gt;this&lt;/code&gt; will be exactly what you have specified. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7i5i3xaiy8ebwpwss06c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7i5i3xaiy8ebwpwss06c.png" alt="step-2-was-function-modified-by-bind-or-call-or-apply-methods" width="792" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Was the function called as a constructor after &lt;code&gt;new&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;If you try to access &lt;code&gt;this&lt;/code&gt; from within a normal function that was not modified by &lt;code&gt;.bind&lt;/code&gt; and your function IS called as a constructor right after &lt;code&gt;new&lt;/code&gt; (for example, &lt;code&gt;new User()&lt;/code&gt;), then inside &lt;code&gt;this&lt;/code&gt; will be that newly created object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5w9qsoufbp8emyslyb1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5w9qsoufbp8emyslyb1y.png" alt="step-3-was-function-called-as-constructor-after-new-keyword" width="792" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Was the function called as an object’s method after a dot?
&lt;/h3&gt;

&lt;p&gt;If you try to access &lt;code&gt;this&lt;/code&gt; from within a normal function that was not modified by you and your function is NOT called as a constructor after &lt;code&gt;new&lt;/code&gt;, but IS called as an object’s method (after a dot), then &lt;code&gt;this&lt;/code&gt; will be the object before the dot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr4ev78rwvv6r3pg7hsau.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr4ev78rwvv6r3pg7hsau.png" alt="step-4-was-function-called-as-method-of-array-after-the-dot" width="792" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Is “use strict” active?
&lt;/h3&gt;

&lt;p&gt;That is the last condition.&lt;/p&gt;

&lt;p&gt;If you try to access &lt;code&gt;this&lt;/code&gt; from within a normal function.&lt;/p&gt;

&lt;p&gt;And that function is NOT modified by &lt;code&gt;.bind&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And that function is NOT called as a constructor after &lt;code&gt;new&lt;/code&gt; and is NOT called as an object’s method.&lt;/p&gt;

&lt;p&gt;The final decision that the engine will make depends on whether “use strict” is enabled.&lt;/p&gt;

&lt;p&gt;If “use strict” is enabled, then the engine will pass &lt;code&gt;undefined&lt;/code&gt; as the value of &lt;code&gt;this&lt;/code&gt;, and if “use strict” is not enabled, then the engine will pass the global object (&lt;code&gt;window&lt;/code&gt;) as the value of &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvakpaq8o90yzcp0y1cem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvakpaq8o90yzcp0y1cem.png" alt="step-5-is-strict-mode-enabled" width="800" height="589"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  That is it. The end.
&lt;/h2&gt;

&lt;p&gt;Congrats🥳&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqwymfenzglzk10e9m10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqwymfenzglzk10e9m10.png" alt="Mission completed" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now you know everything you really need know about &lt;code&gt;this&lt;/code&gt;!&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Examples for consolidation
&lt;/h2&gt;

&lt;p&gt;&lt;/p&gt;
  Click to unfold them
  &lt;h4&gt;
  
  
  Normal separate function in sloppy vs strict mode
&lt;/h4&gt;

&lt;p&gt;Example 1.1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;func1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 1.2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 1.3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;func1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 1.4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sloppyFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;strictFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;sloppyFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;strictFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of example 1.1. In both cases, we have normal, not an arrow function. In both cases, those functions don’t have the “pinned” value of &lt;code&gt;this&lt;/code&gt; explicitly. In both cases, functions are called as plain functions, not as constructors or methods. And in both cases, there are sloppy, not strict modes. So in both cases you will see &lt;code&gt;window&lt;/code&gt; in the console.&lt;/p&gt;

&lt;p&gt;Explanation of example 1.2. We have normal, not an arrow function. That function doesn’t have the “pinned” value of &lt;code&gt;this&lt;/code&gt; explicitly. The function is called a plain function, not a constructor or method. Regardless of whether it was wrapped with another function, that has no sense and impacts on nothing. And of course you see &lt;code&gt;window&lt;/code&gt; in the console.&lt;/p&gt;

&lt;p&gt;Explanation of example 1.3. In both cases, we have normal, not an arrow function. In both cases, those functions don’t have the “pinned” value of &lt;code&gt;this&lt;/code&gt; explicitly. In both cases, functions are called as plain functions, not as constructors or methods.&lt;br&gt;
And because we have strict mode enabled, &lt;code&gt;this&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt;, not &lt;code&gt;window&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Explanation of example 1.4. In both cases, we have normal, not an arrow function. In both cases, those functions don’t have the “pinned” value of &lt;code&gt;this&lt;/code&gt; explicitly. In both cases, functions are called as plain functions, not as constructors or methods.&lt;br&gt;
But the code of the first function runs in sloppy mode, and the code of the second function runs in strict mode.&lt;/p&gt;
&lt;h4&gt;
  
  
  Constructor vs Object's method vs Separate function
&lt;/h4&gt;

&lt;p&gt;Example 2.1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logThis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logThis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 2.2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Constructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SomeClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SomeClass&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 2.3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Constructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;modifyAndLogThis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;67&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;modifyAndLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;modifyAndLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;modifyAndLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 2.4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SloppyConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;randomVal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;StrictConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;randomVal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sloppyFuncAsVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;SloppyConstructor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;strictFuncAsVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;StrictConstructor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;SloppyConstructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;randomVal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;sloppyFuncAsVariable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;randomVal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;strictFuncAsVariable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;StrictConstructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of example 2.1. Function is not an arrow, but normal. Not &lt;code&gt;.bind&lt;/code&gt;, not &lt;code&gt;.call&lt;/code&gt;/&lt;code&gt;.apply&lt;/code&gt; was not used. The function was not called as a constructor after &lt;code&gt;new&lt;/code&gt;, but it was called as a method. And &lt;code&gt;console.log(this)&lt;/code&gt; will log that object. And &lt;code&gt;console.log(this === object)&lt;/code&gt; will be &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Explanation of example 2.2. Functions are not arrow, but normal. Not &lt;code&gt;.bind&lt;/code&gt;, not &lt;code&gt;.call&lt;/code&gt;/&lt;code&gt;.apply&lt;/code&gt; was not used. But as functions are called after the keyword &lt;code&gt;new&lt;/code&gt; (it means as constructors), then the value of &lt;code&gt;this&lt;/code&gt; is that object.&lt;/p&gt;

&lt;p&gt;Explanation of example 2.3. Function is not an arrow, but normal. Not &lt;code&gt;.bind&lt;/code&gt;, not &lt;code&gt;.call&lt;/code&gt;/&lt;code&gt;.apply&lt;/code&gt; was not used.&lt;br&gt;
Even though we declared the function starting with a capital letter and planned to use it as a constructor, we didn’t use it as a constructor. We move that function inside the object and call it as the object’s method. And then during the first function’s call, &lt;code&gt;this&lt;/code&gt; was that object, and the function replaced &lt;code&gt;modifyAndLogThis&lt;/code&gt; with &lt;code&gt;67&lt;/code&gt; . And then during the second call &lt;code&gt;object.modifyAndLogThis&lt;/code&gt; was &lt;code&gt;67&lt;/code&gt;, and &lt;code&gt;67&lt;/code&gt; is a number, not a function, so you see an error in the console.&lt;/p&gt;

&lt;p&gt;Explanation of example 2.4. Function is not an arrow, but normal. Not &lt;code&gt;.bind&lt;/code&gt;, not &lt;code&gt;.call&lt;/code&gt;/&lt;code&gt;.apply&lt;/code&gt; was not used.&lt;br&gt;
Even though we declared the function starting with a capital letter and planned to use it as a constructor, we didn’t use it as a constructor. We called them as plain separate functions.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;.bind&lt;/code&gt;, &lt;code&gt;.call&lt;/code&gt;, &lt;code&gt;.apply&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Example 3.1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sloppyFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;strictFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Constructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// normal calls&lt;/span&gt;

&lt;span class="nf"&gt;sloppyFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;strictFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// explicitly passed values&lt;/span&gt;

&lt;span class="nx"&gt;sloppyFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bam&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;strictFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bam&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bam&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;// new Constructor.apply({bim: "bam"}); // error&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bam&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;sloppyFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bem&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})();&lt;/span&gt;
&lt;span class="nx"&gt;strictFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bem&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})();&lt;/span&gt;
&lt;span class="nx"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bem&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})();&lt;/span&gt;
&lt;span class="c1"&gt;// new Constructor.bind({bom: "bem"})(); // error&lt;/span&gt;
&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;bom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bem&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Errors in two places (where I commented code) will be because it is forbidden to use constructors in that way.&lt;/p&gt;

&lt;p&gt;And results and reasons in other places I think are obvious.&lt;/p&gt;

&lt;h4&gt;
  
  
  An arrow functions
&lt;/h4&gt;

&lt;p&gt;Example 4.1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sloppyArrowFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;sloppyArrowFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;strictArrowFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;strictArrowFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;sloppyArrowFunc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;strictArrowFunc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;object1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;object1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;object2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;object2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;basicArrowFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;basicArrowFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowFuncWithBindedThis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;basicArrowFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
&lt;span class="nf"&gt;arrowFuncWithBindedThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;executeExperiment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sloppyArrowFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nf"&gt;sloppyArrowFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;strictArrowFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nf"&gt;strictArrowFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;sloppyArrowFunc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;strictArrowFunc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nx"&gt;object1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;object1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nx"&gt;object2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sloppyLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;object2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strictLogThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;basicArrowFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;basicArrowFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowFuncWithBindedThis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;basicArrowFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
    &lt;span class="nf"&gt;arrowFuncWithBindedThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;executeExperiment&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 4.2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ArrowConstructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrowConstructor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SomeClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SomeClass&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 4.3.&lt;br&gt;
&lt;strong&gt;This one is the most interesting!&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;buildArrowFunc&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;buildArrowFunc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// short syntax for "buildArrowFunc: buildArrowFunc,"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowFunction1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;buildArrowFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowFunction2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;buildArrowFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;buildArrowFunc&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;buildArrowFunc&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;arrowFunction1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;arrowFunction2&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of example 4.1. Functions are arrow. Again. Functions are arrow. So it &lt;code&gt;.bind&lt;/code&gt;/&lt;code&gt;.call&lt;/code&gt;/&lt;code&gt;.apply&lt;/code&gt; don’t matter. Whether they are methods or not doesn’t matter. Whether they are constructors matters because we can’t use an arrow function as a constructor, but anyway. And whether there is sloppy mode or strict mode, more so doesn’t matter.&lt;br&gt;
Really matters that they are arrow functions and the engine will look for &lt;code&gt;this&lt;/code&gt; within the closure same as for any other variable.&lt;/p&gt;

&lt;p&gt;Explanation of example 4.2. In both cases, there will be errors. In the first case, because an arrow function can’t be a constructor. And in the second case, there is a syntax error.&lt;/p&gt;

&lt;p&gt;Explanation of example 4.3. Here you must pay really huge attention! &lt;code&gt;arrowFunction1&lt;/code&gt; is an arrow one, and &lt;code&gt;arrowFunction2&lt;/code&gt; is an arrow one. And of course, in both cases, the engine looks for the value of &lt;code&gt;this&lt;/code&gt; within the closure, just as it looks for &lt;code&gt;randomNumber&lt;/code&gt;. But those functions have different closures. That is why the values of &lt;code&gt;this&lt;/code&gt; and of &lt;code&gt;randomNumber&lt;/code&gt; are different.&lt;/p&gt;

&lt;p&gt;Nuances of how closures, scope, and lexical environment work are a different interesting topic. Left comment and subscribe if you are interested in and I’ll try to explain that topic as well.&lt;/p&gt;



&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cheatsheet:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Is it an Arrow function?

&lt;ul&gt;
&lt;li&gt;if Yes, then the engine looks for &lt;code&gt;this&lt;/code&gt; through closure, the same as for plain variables.&lt;/li&gt;
&lt;li&gt;if No, then was the function modified by &lt;code&gt;.bind&lt;/code&gt;, &lt;code&gt;.call&lt;/code&gt;, or &lt;code&gt;.apply&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;if Yes, then the engine passes that explicitly provided object as the value of &lt;code&gt;this&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;if No, then was the function called as a constructor after &lt;code&gt;new&lt;/code&gt;?

&lt;ul&gt;
&lt;li&gt;if Yes, then the engine passes the newly created object as the value of &lt;code&gt;this&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;if No, then was function called as object’s method after dot?&lt;/li&gt;
&lt;li&gt;if Yes, then the engine passes the object before the dot as the value of &lt;code&gt;this&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;is 'use strict' active?

&lt;ul&gt;
&lt;li&gt;if Yes, then the engine passes &lt;code&gt;undefined&lt;/code&gt; as the value of &lt;code&gt;this&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;if No, then the engine passes global object (&lt;code&gt;window&lt;/code&gt;) as the 
value of &lt;code&gt;this&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwz4yfrufpg0bfgs8wsu7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwz4yfrufpg0bfgs8wsu7.png" alt="full-schema-about-this-in-javascript-5-simple-steps" width="800" height="1225"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Isn't it simple? 🤓&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>typescript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
