<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>JavaScript on jeffcarp</title>
    <link>/categories/javascript/</link>
    <description>Recent content in JavaScript on jeffcarp</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 12 Jan 2015 00:00:00 +0000</lastBuildDate>
    <atom:link href="/categories/javascript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Visualizing JavaScript Project Structure</title>
      <link>/posts/2015/visualizing-javascript-project-structure/</link>
      <pubDate>Mon, 12 Jan 2015 00:00:00 +0000</pubDate>
      <guid>/posts/2015/visualizing-javascript-project-structure/</guid>
      <description>&lt;p&gt;Recently I thought to myself: fairly frequently I dive into a big JS codebase&#xA;and need to poke around for a while to get acquainted with the project&#xA;structure, wouldn&amp;rsquo;t it be nice if I could have a more visual way of seeing the&#xA;whole thing to make sense of it all?&lt;/p&gt;&#xA;&lt;p&gt;It was this need I was trying to fill when I embarked on my &lt;a href=&#34;https://www.braintreepayments.com/braintrust/walking-the-talk-open-dev-time-at-braintree&#34;&gt;open&#xA;dev&lt;/a&gt;&#xA;project last Friday. In this post I&amp;rsquo;ll try to walk through the steps I took so&#xA;you can replicate them. If you want to just to play with the final project,&#xA;it&amp;rsquo;s available as an npm module named &lt;code&gt;jsviz&lt;/code&gt; (npm:&#xA;&lt;a href=&#34;https://www.npmjs.com/package/jsviz&#34;&gt;jsviz&lt;/a&gt;, GitHub:&#xA;&lt;a href=&#34;https://github.com/jeffcarp/jsviz&#34;&gt;jeffcarp/jsviz&lt;/a&gt;).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Things learned while preparing for Angular Live Code</title>
      <link>/posts/2014/things-learned-preparing-for-angular-live-code/</link>
      <pubDate>Tue, 22 Apr 2014 00:00:00 +0000</pubDate>
      <guid>/posts/2014/things-learned-preparing-for-angular-live-code/</guid>
      <description>&lt;p&gt;This week I learned that there&amp;rsquo;s nothing quite like signing up to teach&#xA;something to make you realize you don&amp;rsquo;t actually know the material all that&#xA;well.&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;m giving an &lt;a href=&#34;http://www.meetup.com/html5livecode/events/173124562/&#34;&gt;introduction to AngularJS&#xA;talk&lt;/a&gt; this Thursday at&#xA;Startup House SF. You should come by if you want to learn about AngularJS.&lt;/p&gt;&#xA;&lt;p&gt;It&amp;rsquo;s Tuesday and 124 people have signed up and I&amp;rsquo;m kind of nervous to say the&#xA;least.  I&amp;rsquo;ve tried to channel my nervousness into preparation (we&amp;rsquo;ll see if it&#xA;pays off or not). Here are a few things I&amp;rsquo;ve learned in the process.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Two interesting IE JavaScript quirks</title>
      <link>/posts/2014/two-ie-js-quirks/</link>
      <pubDate>Fri, 14 Mar 2014 00:00:00 +0000</pubDate>
      <guid>/posts/2014/two-ie-js-quirks/</guid>
      <description>&lt;p&gt;In the past month I&amp;rsquo;ve diagnosed and fixed a couple particularly pernicious&#xA;bugs relating to JavaScript quirks in Internet Explorer. Hopefully if you&#xA;haven&amp;rsquo;t run into these before, this will save you some pain in the future.&lt;/p&gt;&#xA;&lt;h2 id=&#34;1-window-does-not-inherit-from-objectprototype&#34;&gt;1. &lt;code&gt;window&lt;/code&gt; does not inherit from &lt;code&gt;Object.prototype&lt;/code&gt;&lt;/h2&gt;&#xA;&lt;p&gt;Oddly enough, according to the ECMAScript specification, the global &lt;code&gt;window&lt;/code&gt;&#xA;object does not necessarily have to inherit from &lt;code&gt;Object.prototype&lt;/code&gt;. In Chrome,&#xA;FF, and Safari, it does, but in IE it does not.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JavaScript&#39;s Mutative vs. Non-Mutative Array Methods</title>
      <link>/posts/2014/mutative-vs-non-mutative-array-methods-in-js/</link>
      <pubDate>Thu, 20 Feb 2014 12:00:04 +0000</pubDate>
      <guid>/posts/2014/mutative-vs-non-mutative-array-methods-in-js/</guid>
      <description>&lt;p&gt;This is an issue that has endlessly tripped me up in JavaScript and I hope this post will help clarify things a bit and hopefully discover a pattern one can use to discern between mutative and non-mutative array methods.&lt;/p&gt;&#xA;&lt;p&gt;First, let me define what I mean when I say mutative:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// If a method is mutative, that means it changes the original array.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;foo&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;];&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;foo&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;reverse&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;console&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;log&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;foo&lt;/span&gt;); &lt;span style=&#34;color:#75715e&#34;&gt;// [3, 2, 1]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Notice how we didn&amp;#39;t assign foo to new variable, reverse() acted upon it in place.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// In contrast, non-mutative array methods return a new copy of the original array.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Here, the new array concat() generates is lost since we didn&amp;#39;t assign it&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;bar&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;];&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;bar&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;concat&lt;/span&gt;([&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;]);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;console&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;log&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;bar&lt;/span&gt;); &lt;span style=&#34;color:#75715e&#34;&gt;// [1, 2, 3]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Now if we assign it, bar becomes the new array.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;bar&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;bar&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;concat&lt;/span&gt;([&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;]);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;console&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;log&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;bar&lt;/span&gt;); &lt;span style=&#34;color:#75715e&#34;&gt;// [1, 2, 3, 4, 5]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;table&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;th&gt;Mutative&lt;/th&gt;&#xA;    &lt;th&gt;Non-Mutative&lt;/th&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice&#34;&gt;splice&lt;/a&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice&#34;&gt;slice&lt;/a&gt;&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift&#34;&gt;shift&lt;/a&gt;, &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop&#34;&gt;pop&lt;/a&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat&#34;&gt;concat&lt;/a&gt;&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift&#34;&gt;unshift&lt;/a&gt;, &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push&#34;&gt;push&lt;/a&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every&#34;&gt;every&lt;/a&gt; *&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse&#34;&gt;reverse&lt;/a&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter&#34;&gt;filter&lt;/a&gt; *&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort&#34;&gt;sort&lt;/a&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach&#34;&gt;forEach&lt;/a&gt; *&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf&#34;&gt;indexOf&lt;/a&gt;&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf&#34;&gt;lastIndexOf&lt;/a&gt;&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join&#34;&gt;join&lt;/a&gt;&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map&#34;&gt;map&lt;/a&gt; *&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce&#34;&gt;reduce&lt;/a&gt; *&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight&#34;&gt;reduceRight&lt;/a&gt; *&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some&#34;&gt;some&lt;/a&gt; *&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString&#34;&gt;toLocaleString&lt;/a&gt;&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;  &lt;tr&gt;&#xA;    &lt;td&gt;&lt;/td&gt;&#xA;    &lt;td&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString&#34;&gt;toString&lt;/a&gt;&lt;/td&gt;&#xA;  &lt;/tr&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;NB: the functional methods marked with a * can be mutative if the function you pass to them modifies the original array. In my expierience this has been especially true in the case of Array.prototype.forEach.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
