<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Where &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/where/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>JavaScript Objects Coding Style Reviewed</title>
		<link>/2010/12/03/javascript-objects-coding-style-reviewed/</link>
		<comments>/2010/12/03/javascript-objects-coding-style-reviewed/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 10:05:59 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming style]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Where]]></category>

		<guid isPermaLink="false">/?p=2084</guid>
		<description><![CDATA[JS Objects Once I posted about JavaScript object coding style. Back than I made the analogy with PHP array coding style. In breve it&#8217;s useful to format the arrays in PHP simply like that: $data = array( 'key1' =&#62; 'value1', 'key2' =&#62; 'value2', 'key3' =&#62; 'value3', 'key4' =&#62; 'value4', 'key5' =&#62; 'value5', ); Note that &#8230; <a href="/2010/12/03/javascript-objects-coding-style-reviewed/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Objects Coding Style Reviewed</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2010/05/26/php-conditionals-coding-style/" rel="bookmark" title="PHP: Conditionals Coding Style">PHP: Conditionals Coding Style </a></li>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JS Objects</h2>
<p>Once I posted about <a title="JavaScript Objects Coding style" href="/2010/05/24/javascript-objects-coding-style/" target="_blank">JavaScript object coding style</a>. Back than I made the analogy with PHP array coding style. In breve it&#8217;s useful to format the arrays in PHP simply like that:</p>
<pre lang="php" escaped="true">$data = array(
	'key1' =&gt; 'value1',
	'key2' =&gt; 'value2',
	'key3' =&gt; 'value3',
	'key4' =&gt; 'value4',
	'key5' =&gt; 'value5',
);
</pre>
<p>Note that there is a trailing comma after the last key/value pair. This is not a syntax error and helps you add new elements to the array with no fear to forget the comma. This coding standard is quite well known in the PHP community, but in fact writing JavaScript objects can be &#8220;translated&#8221; to something very similar. The only problem is that the trailing comma in JavaScript will result to an error, especially in Internet Explorer, so it is important to remove it.</p>
<pre lang="javascript">
var obj = {
	key1 : 'value1',
	key2 : 'value2',
	key3 : 'value3',
	key4 : 'value4',
	key5 : 'value5'
};
</pre>
<p>The problem is that when you&#8217;ve to add one key/value pair, you&#8217;ve to add the comma after the last pair. This actually makes it useless.</p>
<h2>Better Solution</h2>
<p>There is another way, much better I think, that may help you more when adding new pairs to the object.</p>
<pre lang="javascript">
var obj = 
	{ key1 : 'value1'
	, key2 : 'value2'
	, key3 : 'value3'
	, key4 : 'value4'
	, key5 : 'value5'
	};
</pre>
<p>In this example you can simply copy/paste the last pair and change the key and value, or you can simply can continue writing the way the object is constructed.</p>
<p>Thus you don&#8217;t have the problem with the last comma and syntax errors.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2010/05/26/php-conditionals-coding-style/" rel="bookmark" title="PHP: Conditionals Coding Style">PHP: Conditionals Coding Style </a></li>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/12/03/javascript-objects-coding-style-reviewed/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
