<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: JavaScript Date&#160;to Time</title>
	<atom:link href="http://hexmen.com/blog/2009/12/javascript-date-to-time/feed/" rel="self" type="application/rss+xml" />
	<link>http://hexmen.com/blog/2009/12/javascript-date-to-time/</link>
	<description>On programming, and other things...</description>
	<lastBuildDate>Mon, 30 Jan 2012 07:45:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Tim Down</title>
		<link>http://hexmen.com/blog/2009/12/javascript-date-to-time/comment-page-1/#comment-31444</link>
		<dc:creator>Tim Down</dc:creator>
		<pubDate>Tue, 05 Jan 2010 00:35:59 +0000</pubDate>
		<guid isPermaLink="false">http://hexmen.com/blog/?p=98#comment-31444</guid>
		<description>Ash,

I have nothing but approval and joy for negative offsets in substr and slice. I think it&#039;s pretty intuitive and much easier to read than the equivalent with messing around with subtracting the string&#039;s length. It doesn&#039;t at all look as though it&#039;s showing off, unlike +new Date.

As it happens, I knew about the unary + operator and optional parentheses for constructors but not the negative offsets for slice and substr, so thank you for alerting me to that.

Tim</description>
		<content:encoded><![CDATA[<p>Ash,</p>
<p>I have nothing but approval and joy for negative offsets in substr and slice. I think it&#8217;s pretty intuitive and much easier to read than the equivalent with messing around with subtracting the string&#8217;s length. It doesn&#8217;t at all look as though it&#8217;s showing off, unlike +new Date.</p>
<p>As it happens, I knew about the unary + operator and optional parentheses for constructors but not the negative offsets for slice and substr, so thank you for alerting me to that.</p>
<p>Tim</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ash</title>
		<link>http://hexmen.com/blog/2009/12/javascript-date-to-time/comment-page-1/#comment-31412</link>
		<dc:creator>Ash</dc:creator>
		<pubDate>Wed, 16 Dec 2009 14:21:53 +0000</pubDate>
		<guid isPermaLink="false">http://hexmen.com/blog/?p=98#comment-31412</guid>
		<description>Hi Dan,

I&#039;m still learning myself...

There&#039;s an annoying caveat with &lt;code&gt;substr&lt;/code&gt;: you can pass negative indexes as the first parameter, but not the second.  Fortunately &lt;code&gt;slice&lt;/code&gt; has you covered:

&lt;pre&gt;&lt;code&gt;
// from the bowels of jQuery (removeClass)
var className = &quot; &quot; + elem.className + &quot; &quot;;
// remove named classes (omitted), and replace:
elem.className = className.substring(1, className.length - 1);

// use slice to remove single leading and trailing space:
elem.className = className.slice(1, -1);
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi Dan,</p>
<p>I&#8217;m still learning myself&#8230;</p>
<p>There&#8217;s an annoying caveat with <code>substr</code>: you can pass negative indexes as the first parameter, but not the second.  Fortunately <code>slice</code> has you covered:</p>
<pre><code>
// from the bowels of jQuery (removeClass)
var className = " " + elem.className + " ";
// remove named classes (omitted), and replace:
elem.className = className.substring(1, className.length - 1);

// use slice to remove single leading and trailing space:
elem.className = className.slice(1, -1);
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Beam</title>
		<link>http://hexmen.com/blog/2009/12/javascript-date-to-time/comment-page-1/#comment-31411</link>
		<dc:creator>Dan Beam</dc:creator>
		<pubDate>Wed, 16 Dec 2009 05:50:17 +0000</pubDate>
		<guid isPermaLink="false">http://hexmen.com/blog/?p=98#comment-31411</guid>
		<description>Ash,

You&#039;ve saved us some time and a few characters with the few things we just learned from this post, haha:

1) + converts to a number (by implicitly calling valueOf)
2) default constructors require no () at the end, that&#039;s cool
3) you can use a negative index in String.prototype.substr

We knew PHP had this functionality (in substr()), but we had no clue you could do this in JavaScript without modifying String&#039;s prototype.

Thank you,

All my future websites</description>
		<content:encoded><![CDATA[<p>Ash,</p>
<p>You&#8217;ve saved us some time and a few characters with the few things we just learned from this post, haha:</p>
<p>1) + converts to a number (by implicitly calling valueOf)<br />
2) default constructors require no () at the end, that&#8217;s cool<br />
3) you can use a negative index in String.prototype.substr</p>
<p>We knew PHP had this functionality (in substr()), but we had no clue you could do this in JavaScript without modifying String&#8217;s prototype.</p>
<p>Thank you,</p>
<p>All my future websites</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ash</title>
		<link>http://hexmen.com/blog/2009/12/javascript-date-to-time/comment-page-1/#comment-31380</link>
		<dc:creator>Ash</dc:creator>
		<pubDate>Wed, 09 Dec 2009 09:17:57 +0000</pubDate>
		<guid isPermaLink="false">http://hexmen.com/blog/?p=98#comment-31380</guid>
		<description>@Tim,

I agree - using dark magic can make code awkward to understand and hard to maintain.

However, I came across the three styles in the bowels of widespread JavaScript libraries which aim for stability and compactness.  In these cases I&#039;d expect the libraries to go with the most compact and efficient implementation.

There&#039;s another widespread idiom that avoids deep JavaScript knowledge: do you feel the same way about this - checking the end of a string:

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;var summat = &quot;foobar&quot;, tail = &quot;bar&quot;;
// common idiom for Java&#039;s endsWith:
if (summat.substring(summat.length - tail.length) == tail) …

// using knowledge of substr:
if (summat.substr(-tail.length) == tail) …

// For hard-coded tails - compare the substring and substr versions:
if (path.substring(path.length - 1) == &#039;/&#039;) …

if (path.substr(-1) == &#039;/&#039;) …
&lt;/code&gt;&lt;/pre&gt;

I&#039;d guess a lot of JavaScript coders don&#039;t know they can use negative offsets in &lt;code&gt;substr&lt;/code&gt;, but it doesn&#039;t seem quite so &lt;em&gt;deep&lt;/em&gt; as &lt;code&gt;+new Date&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>@Tim,</p>
<p>I agree &#8211; using dark magic can make code awkward to understand and hard to maintain.</p>
<p>However, I came across the three styles in the bowels of widespread JavaScript libraries which aim for stability and compactness.  In these cases I&#8217;d expect the libraries to go with the most compact and efficient implementation.</p>
<p>There&#8217;s another widespread idiom that avoids deep JavaScript knowledge: do you feel the same way about this &#8211; checking the end of a string:</p>
<pre><code class="javascript">var summat = "foobar", tail = "bar";
// common idiom for Java's endsWith:
if (summat.substring(summat.length - tail.length) == tail) …

// using knowledge of substr:
if (summat.substr(-tail.length) == tail) …

// For hard-coded tails - compare the substring and substr versions:
if (path.substring(path.length - 1) == '/') …

if (path.substr(-1) == '/') …
</code></pre>
<p>I&#8217;d guess a lot of JavaScript coders don&#8217;t know they can use negative offsets in <code>substr</code>, but it doesn&#8217;t seem quite so <em>deep</em> as <code>+new Date</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Harwood</title>
		<link>http://hexmen.com/blog/2009/12/javascript-date-to-time/comment-page-1/#comment-31369</link>
		<dc:creator>Scott Harwood</dc:creator>
		<pubDate>Tue, 08 Dec 2009 00:38:13 +0000</pubDate>
		<guid isPermaLink="false">http://hexmen.com/blog/?p=98#comment-31369</guid>
		<description>Me neither. I do think that embracing the nature of the language rather than molding it into another is.</description>
		<content:encoded><![CDATA[<p>Me neither. I do think that embracing the nature of the language rather than molding it into another is.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

