{"id":4719,"date":"2018-10-03T23:55:09","date_gmt":"2018-10-03T23:55:09","guid":{"rendered":"https:\/\/tinjurewp.com\/jsblog\/?p=40"},"modified":"2018-10-03T23:55:09","modified_gmt":"2018-10-03T23:55:09","slug":"understanding-this-keyword-in-javascript","status":"publish","type":"post","link":"https:\/\/learncode.tinjurewp.com\/understanding-this-keyword-in-javascript\/","title":{"rendered":"Understanding this Keyword in JavaScript"},"content":{"rendered":"<p class=\"note icon-note\"><strong>Note<\/strong>: This post is work-in-progress learning-note and still in active development. This was initially drafted on March 8 and updated recently.<\/p>\n<p>In JavaScript (JS), use of function&#8217;s <code>this<\/code> keyword is very confusing, it means different thing depending on the context how a function is called. There is also some difference in whether this is called in <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Functions_and_function_scope\/Strict_mode\" target=\"_blank\" rel=\"noopener\">strict mode<\/a> or <em>non-strict<\/em> mode. For example, Is it used outside of a function? Is it a regular function call? Methods in ES6 classes? Called in an arrow function? etc. Based on how a function is called, value of <code>this<\/code> could be different. Even more confusing is that <code>this<\/code> keyword will have different value in the same function depending upon whether it is called as a\u00a0 object method or callback function.<\/p>\n<p>In this learning-note post, how the value of <code>this<\/code> keyword differs in different context is discussed.<\/p>\n<h5>1. Global Context<\/h5>\n<p>When <code>this<\/code> keyword is used outside of a function in a browser, it refers to global object. In a a browser, global object refers to window.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/used in browser \nconsole.log(this === window); \/\/ OUTPUT =&gt;true\n\/\/assign variable\ngreeting = &quot;Hello World!&quot;;\nconsole.log(window.greeting); \/\/ OUTPUT =&gt;Hello World!\n\/\/ this.var asignment\nthis.year = 2018;\nconsole.log(window.year); \/\/ OUTPUT =&gt; 2018\nconsole.log(year); \/\/ OUTPUT =&gt; 2018<\/code><\/pre>\n<p>In the example above, <code>this<\/code> when used in a browser refers to <code>window<\/code> (line 2). Likewise, a global variable (outside of a function) also refers to window (lines: 4-5). In line 7, <code>this.year<\/code> is assigned to <code>2018<\/code>, which refers to <code>window<\/code> object as well (lines: 8-9).<\/p>\n<h5>2. Simple Function Call<\/h5>\n<p>When calling a function in non-strict mode, <code>this<\/code> refers to global object, which is window in a browser.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/define a function\nfunction greeting() {\n  return this;\n}\n\/\/in a browser\ngreeting() === window; \/\/ OUTPUT = true<\/code><\/pre>\n<p>In non-strict mode, <code>this<\/code> in function call refers to global (window) object (line: 6) because the value of <code>this<\/code> is not set by call. In strict mode, the value of <code>this<\/code> remains at <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#Simple_call\" target=\"_blank\" rel=\"noopener\">whatever it was set to when entering the execution context<\/a>.<\/p>\n<pre class=\"line-numbers\" data-start=\"7\"><code class=\"language-javascript\">\/\/simple function\nfunction greeting() {\n  &#039;use strict&#039;; \/\/strict mode\n  return this;\n}\n\/\/invoke greeting()\ngreeting(); \/\/ OUTPUT =&gt; undefined\ngreeting() === undefined; \/\/ OUTPUT =&gt; true<\/code><\/pre>\n<p>In the example above, <code>this<\/code> defaults to <code>undefined<\/code> (lines: 13-14) because it was not defined and called directly not as <em>method<\/em> or <em>property of an object<\/em> (see explanation below).<\/p>\n<p><strong>Setting a <code>this<\/code> Value<\/strong>: Value of <code>this<\/code> keyword can be set to current context by assigning a value to <code>this<\/code> as shown in the example below:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/define a function\nfunction greeting() {\n  this.msg = &quot;Hello World!&quot;;\n  return this;\n}\n\/\/in a browser\nconsole.log(greeting()); \/\/OUTPUT =&gt; window\nconsole.log(new greeting()); \/\/OUTPUT =&gt; greeting {msg: &quot;Hello World!&quot;}<\/code><\/pre>\n<p>In the example above,\u00a0 the <code>greeting()<\/code> logs to global (window) scope (line 7). However when it is invoked with new constructor operator as <code>new greeting()<\/code> it returns as <code>greeting\u00a0{msg: &quot;Hello World!&quot;}<\/code> because the <code>new<\/code> operator bounds the value of <code>this<\/code> to the instance <code>greeting()<\/code> as shown in line 8.<\/p>\n<p>Passing the value of <code>this<\/code> from one context to another will be discussed below in a separate section.<\/p>\n<h5>a. Setting <code>this<\/code> value with <code>call()<\/code>, <code>apply()<\/code> &amp; <code>bind()<\/code> Methods<\/h5>\n<p>When a function is called directly or a property of an object then it returns global (window) because this is not bound and not aware of its calling function. This problem can be fixed by passing this value from one context to another using <code>&lt;a href=&quot;https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/call&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;call()&lt;\/a&gt;<\/code> or <code>&lt;a href=&quot;https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/apply&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;apply()&lt;\/a&gt;<\/code> method as shown below:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/ define helloWorld object\nvar helloWorld = {msg: &#039;Hello World!&#039;};\n\n\/\/global context\nvar msg = &quot;Hello USA!&quot;;\n\n\/\/ define function\nfunction valueOfThis() {\n  return this.msg; \/\/ value depends how it is called\n}\n\/\/invoke function\nvalueOfThis(); \/\/ OUTPUT =&gt; &quot;Hello USA!&quot;\n\/\/set with call()\nvalueOfThis.call(helloWorld); \/\/ OUTPUT =&gt; &quot;Hello World!&quot;\n\/\/set with apply()\nvalueOfThis.apply(helloWorld); \/\/ OUTPUT =&gt; &quot;Hello World!&quot;<\/code><\/pre>\n<p>In the example above (adopted from <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#Simple_call\" target=\"_blank\" rel=\"noopener\">MDN<\/a>) value of <code>this<\/code> keyword in <code>valueOfThis()<\/code> call (line ) refers to global variable <code>&quot;Hello World!&quot;<\/code> defined inline 5. If and when a <code>this<\/code> keyword is used in function body (eg. <code>valueOfThis()<\/code> in line 9), then value of <code>this<\/code> can be bound to an object in the function call using the <code>call()<\/code> and <code>apply()<\/code> methods.<\/p>\n<p>All functions inherit <code>call()<\/code>, <code>apply()<\/code>, <code>bind()<\/code> methods from <code>&lt;a href=&quot;https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function#Methods&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;function.prototype&lt;\/a&gt;<\/code>, which are defined in MDN documents as follows:<\/p>\n<ul>\n<li><a title=\"The apply() method calls a function with a given this value, and arguments provided as an array (or an array-like object).\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/apply\"><code>Function.prototype.apply()<\/code><\/a>: Calls a function and sets its <em>this<\/em> to the\u00a0provided value, arguments can be passed as an <a title=\"The JavaScript Array\u00a0object is a global object that\u00a0is used in the\u00a0construction\u00a0of\u00a0arrays; which are high-level, list-like objects.\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\"><code>Array<\/code><\/a> object.<\/li>\n<li><a title=\"The call() method calls a function with a given this value and arguments provided individually.\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/call\"><code>Function.prototype.call()<\/code><\/a>: Calls (executes) a function and sets its <em>this <\/em>to the provided value, arguments can be passed as they are.<\/li>\n<li><a title=\"The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/bind\"><code>Function.prototype.bind()<\/code><\/a>: Creates a new function which, when called, has its <em>this<\/em> set to the provided value, with a given sequence of arguments preceding any provided when the new function was called.<\/li>\n<\/ul>\n<h5>b. Using <code>this<\/code> with <code>bind()<\/code> Method<\/h5>\n<p>The <code>bind()<\/code> method attaches an object to a function permanently so that when the function is called it refers to the same bound object. To quote from <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#The_bind_method\" target=\"_blank\" rel=\"noopener\">MDN<\/a> \u2013 when a such an object bound function is called it <em>\u201ccreates a new function with the same body and scope as the object-bound function, but where <code>this<\/code> occurs in the original function, in the new function it is permanently bound to the first argument of <code>bind<\/code>, regardless of how the function is being used\u201d<\/em>.<\/p>\n<p>Lets examine <code>this<\/code> in the following example:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/function with this in the body\nfunction greeting() {\n  return this.msg;\n}\n\/\/bind object with function\nlet bindValue1 = greeting.bind({msg: &#039;Hello World!&#039;});\nconsole.log(bindValue1()); \/\/OUTPUT =&gt; Hello World!\n\n\/\/re-assign new value to org arg\nlet bindValue2 = bindValue1.bind({msg: &#039;Hello USA!&#039;});\n\/\/bind value can&#039;t be modified\nconsole.log(bindValue2()); \/\/OUTPUT =&gt; Hello World!<\/code><\/pre>\n<p>In the example above (adapted from <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#The_bind_method\" target=\"_blank\" rel=\"noopener\">MDN<\/a>), <code>this<\/code> keyword is used in <code>greeting()<\/code> function body (lines: 2-4). The <code>greeting()<\/code> function is <em>bind<\/em> with <code>msg<\/code> object in line 6, which outputs expected <code>Hello World!<\/code> (line 7). The <code>bind()<\/code> method works only once (line 10) and the original value can&#8217;t be re-assigned (line 12).<\/p>\n<h5>3. In Object Methods<\/h5>\n<p>A method is a function and its an property of an object. The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#As_an_object_method\" target=\"_blank\" rel=\"noopener\">MDN<\/a> states that &#8220;<em>when a function is called as a method of an object, its <code>this<\/code> is set to the object the method is called on<\/em>&#8220;.<\/p>\n<p>In the example below, <code>helloWorld<\/code> object (line 2) has <code>msg()<\/code> method defined inside body (lines: 5-7). When <code>helloWorld.msg<\/code> is invoked (line 10), value of this inside <code>msg()<\/code> method (line 10) refers to <code>helloWorld<\/code> object where it is bound.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/expression function\nconst helloWorld = {\n  greeting: &quot;Hello World!&quot;,\n  \/\/ define method\n  msg() {\n    console.log(`${this.greeting} We are live.`);\n  }\n};\n\/\/invoke\nhelloWorld.msg(); \/\/ OUTPUT =&gt; Hello World! We are live.<\/code><\/pre>\n<p>In the above example, the <code>msg()<\/code> function is defined during <code>helloWorld<\/code> object definition method. Behavior of <code>this<\/code> is not affected how or where the function is defined.<\/p>\n<pre class=\"line-numbers\" data-start=\"11\"><code class=\"language-javascript\">\/\/define object\nvar helloWorld = {\n  greeting: &quot;Hello World!&quot;};\n\n\/\/define function\n  function msg() {\n    return this.greeting;\n  }\n\/\/assign function to variable\nhelloWorld.msg = msg;\n\/\/invoke function\nconsole.log(helloWorld.msg()); \/\/OUTPUT =&gt; Hello World!<\/code><\/pre>\n<p>In the example above, <code>helloWorld<\/code> object (line:\u00a012-13) is defined. The <code>this<\/code> keyword is used in <code>msg()<\/code> function (line 17) and attached to earlier object as <code>helloWorld.msg<\/code> (line 20), which returns the same output (line 22) as in previous example (line 10). It is important that when invoked function should be member of the object.<\/p>\n<h5>4. In Constructor Operator Context<\/h5>\n<p>Value of <code>this<\/code> keyword can be set to current context by assigning a value to <code>this<\/code> as shown in the example below:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/define a function\nfunction greeting() {\n  this.msg = &quot;Hello World!&quot;;\n  return this;\n}\n\/\/in a browser\nconsole.log(greeting()); \/\/OUTPUT =&gt; window\nconsole.log(new greeting()); \/\/OUTPUT =&gt; greeting\u00a0{msg: &quot;Hello World!&quot;}<\/code><\/pre>\n<p>In the example above,\u00a0 the <code>greeting()<\/code> logs to global (window) scope (line 7). However when it is invoked with new constructor operator as <code>new greeting()<\/code> it returns as <code>greeting\u00a0{msg: &quot;Hello World!&quot;}<\/code> because the <code>new<\/code>operator bounds the value of <code>this<\/code> to the instance <code>greeting()<\/code> as shown in line 8. Passing the value of <code>this<\/code> from one context to another will be discussed below in a separate section.<\/p>\n<p>The value of <code>this<\/code> keyword is bound to the newly constructed object, when a function is used to create new object instance using <code>new<\/code> keyword. Using the previous example with some modification:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/function expression\nfunction greeting() {\n  this.text = &quot;Hello World!&quot;;\n}\n\/\/create new greeting instance\nlet annoucement = new greeting();\nconsole.log(annoucement.text);  \/\/OUTPUT =&gt; Hello World!<\/code><\/pre>\n<p>In the example above, the value of <code>this.text<\/code> (line 3) from <code>greeting()<\/code> is bound to newly constructed object instance of <code>greeting()<\/code> stored in <code>annoucement<\/code> variable (line 6) and hence returns correct <code>text<\/code> value in console output (line 7).<\/p>\n<pre class=\"line-numbers\" data-start=\"8\"><code class=\"language-javascript\">\/\/function expression\nfunction localGreeting() {\n  this.text = &quot;Hello World!&quot;;\n  return {text: &quot;Hello USA!&quot;};\n}\n\/\/create new localGreeting instance\nlet annoucement = new localGreeting();\nconsole.log(annoucement.text); \/\/OUTPUT =&gt; Hello USA!<\/code><\/pre>\n<p>In the example above, because <code>localGreeting()<\/code> was returned during the object instance construction, the bound <code>this.text = &quot;Hello World!&quot;<\/code> gets discarded (line 10). Therefore, in the newly created object instance the <code>text<\/code> (line 14) refers to the returned value from line 11 and NOT the <code>this<\/code> bound value from line 10.<\/p>\n<h5>5. In Arrow Functions<\/h5>\n<p>The arrow functions don&#8217;t have their own <code>this<\/code> keyword, <code>this<\/code> refers the value of enclosing lexical scope. In global context, its value is set to global object (which is window object in a browser line 6) as shown below:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/initialize global object\nlet globalObj = this;\n\/\/arrow function\nlet myFunc = (() =&gt; this);\nconsole.log(myFunc() === globalObj); \/\/ OUTPUT =&gt; true\nconsole.log(myFunc() === window); \/\/ OUTPUT =&gt; true<\/code><\/pre>\n<p>In the example above, value of <code>this<\/code> is stored in <code>globalObj<\/code> variable (line 2). When it is compared with <code>this<\/code> value stored inside <code>myFunc()<\/code> arrow function (line 4) it outputs <code>true<\/code> (line 5) which is equivalent to <code>window<\/code> object in browser (line 6).<\/p>\n<p><strong>The value of <code>this<\/code> in arrow function can&#8217;t be SET explicitly.<\/strong> That means value of <code>this<\/code> can&#8217;t be modified with\u00a0 <code>apply()<\/code>, <code>call()<\/code> or <code>bind()<\/code> methods. The value of <code>this<\/code> refers permanently to the value set when the arrow function was created.<\/p>\n<pre class=\"line-numbers\" data-start=\"7\"><code class=\"language-javascript\">\/\/ call as a method of an object\nlet localObj = {otherFunc: myFunc};\nconsole.log(localObj.otherFunc() === globalObj); \/\/ OUTPUT =&gt; true\n\n\/\/ set this with call()\nconsole.log(myFunc.call(localObj) === globalObj); \/\/ OUTPUT =&gt; true\n\n\/\/ set this with bind()\nmyFunc = myFunc.bind(localObj);\nconsole.log(myFunc() === globalObj); \/\/ OUTPUT =&gt; true<\/code><\/pre>\n<p>In the above example (adopted from <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#Arrow_functions\" target=\"_blank\" rel=\"noopener\">MDN<\/a>), the value of <code>this<\/code> in <code>myFunc()<\/code> arrow function was set to <code>globalObj<\/code> (line 2) when it was created. The value of <code>this<\/code> can&#8217;t be modified from the original <code>globalObj<\/code> by calling as a method of an object (line 8-9), or set explicitly using <code>call()<\/code> method (line 12) or <code>bind()<\/code> method (lines: 15-16).<\/p>\n<p>The value of <code>this<\/code> in <strong>arrow functions<\/strong> created inside other function, will have the same value that of enclosing lexical context. Revisiting example used the <a href=\"https:\/\/tinjurewp.com\/jsblog\/understanding-javascript-arrow-functions\/\" target=\"_blank\" rel=\"noopener\">Understanding JavaScript Arrow Function<\/a> post as shown below:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-javascript\">\/\/create helloWorld object\nlet helloWorld = {\n  greeting: &quot;Hello World!&quot;,\n  \/\/define method\n  msg: function() { \n    console.log(`${this.greeting} We are live.`);\n    \/\/autonomous arrow function\n    setTimeout(() =&gt; {\n      console.log(this.greeting)\n    }, 1000)\n  }\n}\n\/\/invoke\nhelloWorld.msg(); \/\/OUTPUT =&gt;Hello World! We are live.\n\/\/after timeout -- greeting \nHello World!<\/code><\/pre>\n<p>In the example above, value of <code>this<\/code> in <code>msg()<\/code> refers to <code>helloWordl<\/code> object loging <code>msg.greeting<\/code> within the function (line 5) correctly prints <code>&quot;hello World!<\/code> in the output (line 14). When a second <code>setTimeout()<\/code> arrow function is added (lines: 8-10 ), the context of <code>this.greeting<\/code> is different.<\/p>\n<p>Because arrow functions take their value of <code>this<\/code> from the lexical scope (meaning from its surrounding block) and thus captures <code>this<\/code> from its surrounding context <code>helloWorld<\/code> (line 2) where it is <strong>defined<\/strong>. This is discussed in more detail in <a href=\"https:\/\/tinjurewp.com\/jsblog\/understanding-javascript-arrow-functions\/\" target=\"_blank\" rel=\"noopener\">arrow function<\/a> post&#8217;s <em>No Separate this binding<\/em> section.<\/p>\n<h5>6. <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#As_a_DOM_event_handler\" target=\"_blank\" rel=\"noopener\">In DOM Event Handler<\/a><\/h5>\n<p>The <code>this<\/code> keyword use in DOM event handler is discussed in the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this#As_a_DOM_event_handler\" target=\"_blank\" rel=\"noopener\">MDN<\/a> where <code>this<\/code> is set to element where it is fired from. This topic will be discussed in a separate post later.<\/p>\n<h5>Wrapping Up<\/h5>\n<p>Until recently I was very confused with <code>this<\/code> keyword in JavaScript. Because I was just starting to learn <strong>JS Basics<\/strong> it didn\u2019t make much sense to me and was a mystery. When I did a google search with \u2018<em>this in JavaScript<\/em>\u2018, I found many detailed posts about the use of\u00a0 <code>this<\/code> keyword. Indeed I was not alone to get confused.\u00a0 A clear understanding of <code>this<\/code> keyword is important.<\/p>\n<h6>Useful Resources and Links<\/h6>\n<p>While preparing this post, I have referred the following references extensively. Please to refer original posts for more detailed information.<\/p>\n<ul>\n<li><a href=\"https:\/\/dmitripavlutin.com\/gentle-explanation-of-this-in-javascript\/\" target=\"_blank\" rel=\"noopener\">Gentle explanation of \u2018<code>this<\/code>\u2019 keyword in JavaScript<\/a> \u2013 by <em>Dmitri Pavlutin<\/em> (<a href=\"https:\/\/dmitripavlutin.com\/\" target=\"_blank\" rel=\"noopener\"><strong>dmitripavlutin.com<\/strong><\/a>). Very comprehensive post regarding the use of <code>this<\/code> keyword.<\/li>\n<li><a href=\"https:\/\/www.vojtechruzicka.com\/javascript-this-keyword\/\" target=\"_blank\" rel=\"noopener\">Javascript: Uncovering mysteries of \u2018this\u2019 keyword<\/a> &#8211; by <em>Vojtech Ruzicka<\/em> (<a href=\"https:\/\/www.vojtechruzicka.com\/\" target=\"_blank\" rel=\"noopener\">vojtechruzicka.com<\/a>)<\/li>\n<li><a href=\"https:\/\/zellwk.com\/blog\/this\/\" target=\"_blank\" rel=\"noopener\"><code>This<\/code> in JavaScript<\/a> \u2013 by <em>Zell Liew<\/em> (<a href=\"https:\/\/zellwk.com\/blog\/\" target=\"_blank\" rel=\"noopener\"><strong>zellwk.com\/blog<\/strong><\/a>)<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/this\" target=\"_blank\" rel=\"noopener\">Functions this Keyword<\/a> \u2013 MDN Web Docs \u2013 JavaScript Reference.<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\/bind\" target=\"_blank\" rel=\"noopener\">Function .prototype .bind()<\/a> \u2013 MDN Reference<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Note: This post is work-in-progress learning-note and still in active development. This was initially drafted on March 8 and updated recently. In JavaScript (JS), use of function&#8217;s this keyword is very confusing, it means different thing depending on the context how a function is called. There is also some difference in whether this is called [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,50],"tags":[],"class_list":["post-4719","post","type-post","status-publish","format-standard","hentry","category-javascript","category-this-keyword"],"_links":{"self":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/4719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/comments?post=4719"}],"version-history":[{"count":0,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/4719\/revisions"}],"wp:attachment":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/media?parent=4719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/categories?post=4719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/tags?post=4719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}