<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Programming on khz</title><link>https://blog.khzaw.dev/tags/programming/</link><description>Recent content in Programming on khz</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 21 Mar 2017 00:00:00 +0800</lastBuildDate><atom:link href="https://blog.khzaw.dev/tags/programming/index.xml" rel="self" type="application/rss+xml"/><item><title>Self-referencing Keys in JavaScript Object Declarations</title><link>https://blog.khzaw.dev/posts/self-references-in-object-declarations-in-javascript/</link><pubDate>Tue, 21 Mar 2017 00:00:00 +0800</pubDate><guid>https://blog.khzaw.dev/posts/self-references-in-object-declarations-in-javascript/</guid><description>&lt;p&gt;Often times while programming in JavaScript, which I have been doing a lot lately, I find myself wanting to refer to a key that I have just declared when I am initializing an object.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myNewObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;xxx&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;yyy&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;a&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;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// doesn&amp;#39;t work
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myNewObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here, neither &lt;code&gt;a&lt;/code&gt; or &lt;code&gt;this.b&lt;/code&gt; would work since there is no &lt;code&gt;a&lt;/code&gt; yet while &lt;code&gt;c&lt;/code&gt; is being defined and &lt;code&gt;this&lt;/code&gt; does not refer to &lt;code&gt;myNewObj&lt;/code&gt;. Obviously, you could define &lt;code&gt;xxx&lt;/code&gt; and &lt;code&gt;yyy&lt;/code&gt; in separate variables first and refer to them later in the object initialization. Or you could initialize the object without &lt;code&gt;c&lt;/code&gt; key and later define &lt;code&gt;c&lt;/code&gt; as &lt;code&gt;myNewObj.c = myNewObj.a + myNewObj.b;&lt;/code&gt;. But a neater way that I found out is to utilize &lt;code&gt;getters&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Finding A Knight's Tour</title><link>https://blog.khzaw.dev/posts/finding-a-knights-tour/</link><pubDate>Fri, 12 Feb 2016 00:00:00 +0800</pubDate><guid>https://blog.khzaw.dev/posts/finding-a-knights-tour/</guid><description>&lt;figure&gt;&lt;img src="https://blog.khzaw.dev/img/chess-knight_hu_dc022dd327205ba2.webp" alt="" loading="lazy" decoding="async" width="1024" height="685"&gt;&lt;/figure&gt;

&lt;p&gt;A Knight&amp;rsquo;s Tour is a sequence of moves done by a knight on a chessboard such that it visits each and every square exactly once. Subsequently, the objective of &lt;a href="https://en.wikipedia.org/wiki/Knight%27s_tour"&gt;the Knight&amp;rsquo;s Tour problem&lt;/a&gt; is to determine whether there exists a Knight&amp;rsquo;s Tour from a given starting position. In graph theory terms, it is a form of Hamiltonian path where you visit each vertex of the graph exactly once along the path. Tours can also be &lt;strong&gt;cyclic&lt;/strong&gt; or &lt;strong&gt;closed&lt;/strong&gt; if the final square is a knight&amp;rsquo;s move away from the first and &lt;strong&gt;acyclic&lt;/strong&gt; or &lt;strong&gt;open&lt;/strong&gt; otherwise.&lt;/p&gt;</description></item></channel></rss>