{"id":851,"date":"2016-06-29T22:53:17","date_gmt":"2016-06-30T03:53:17","guid":{"rendered":"http:\/\/rpchurchill.com\/?p=851"},"modified":"2017-02-17T10:38:16","modified_gmt":"2017-02-17T15:38:16","slug":"reproducing-a-clever-animation-product-part-18","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/06\/29\/reproducing-a-clever-animation-product-part-18\/","title":{"rendered":"Reproducing A Clever Animation Product, Part 18"},"content":{"rendered":"<p>Yesterday I wrote about how you&#8217;re supposed to be able to process conditional function parameters in JavaScript:<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      function addTransformToList(sElement,tDuration,trans,tAdjustment,mMethod) {\r\n        var tAdjustment = typeof tAdjustment !== \"undefined\" tAdjustment : \"\";\r\n        var mMethod = typeof mMethod !== \"undefined\" mMethod : \"linear\";\r\n        ...\r\n      }\r\n<\/pre>\n<p> The <em>teeeensy<\/em> little problem is that neither browsers nor syntax checkers in certain development tools (WebStorm, in my case, I used it to check my code when editing in Notepad++ and running the Firefox debugger wasn&#8217;t getting me anywhere) will accept this configuration.  The individual pieces are all fine, they just don&#8217;t actually work when you use them together.<\/p>\n<p>Therefore I rewrote the code longhand and, <em>voil\u00e0<em>, it worked!<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      function addTransformToList(sElement,tDuration,trans,imMethod,itAdjustment) {\r\n        var mMethod;\r\n        if ((typeof imMethod) === \"undefined\") {\r\n          mMethod = \"linear\";\r\n        } else {\r\n          mMethod = imMethod;\r\n        }\r\n        \/\/interpreter really chokes on this!\r\n        \/\/var mMethod = (typeof mMethod !== \"undefined\") mMethod : \"linear\";\r\n        \/\/interpreter halfway accepts this, but only halfway\r\n        \/\/var mMethod = (typeof mMethod === \"undefined\") \"linear\" : mMethod;\r\n        var tAdjustment;\r\n        if ((typeof itAdjustment) === \"undefined\") {\r\n          tAdjustment = \"\";\r\n        } else {\r\n          tAdjustment = itAdjustment;\r\n        }\r\n        \/\/var tAdjustment = ((typeof tAdjustment) === \"undefined\") \"\" : tAdjustment;\r\n<\/pre>\n<p>Obviously one <a href=\"\">should not believe everything you read<\/a> on the internet&#8211;especially if you only read the first part of it.  If you <strong>read just a little bit further down in the link<\/strong> you see that the following should work, at least in some browsers:<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      function addTransformToList(sElement,tDuration,trans,mMethod = \"linear\",tAdjustment = \"\") {\r\n        ...\r\n      }\r\n<\/pre>\n<p>I can confirm that this works, at least in Firefox.<\/p>\n<p>Addendum, February 17, 2017:  This a) would have been better if I&#8217;d actually put the link data in the link (I&#8217;m guessing it&#8217;d be real hard to find again) and b) I&#8217;ve since learned that this behavior is one of the differences between ES5 and ES6, which I didn&#8217;t pick up on at the time.  The version of WebStorm I was using was not processing ES6 constructs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I wrote about how you&#8217;re supposed to be able to process conditional function parameters in JavaScript: function addTransformToList(sElement,tDuration,trans,tAdjustment,mMethod) { var tAdjustment = typeof tAdjustment !== &#8220;undefined&#8221; tAdjustment : &#8220;&#8221;; var mMethod = typeof mMethod !== &#8220;undefined&#8221; mMethod : &#8220;linear&#8221;; &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/06\/29\/reproducing-a-clever-animation-product-part-18\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[87,107,101,49],"_links":{"self":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/851"}],"collection":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/comments?post=851"}],"version-history":[{"count":3,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/851\/revisions"}],"predecessor-version":[{"id":1641,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/851\/revisions\/1641"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}