{"id":3040,"date":"2014-06-11T20:48:13","date_gmt":"2014-06-11T20:48:13","guid":{"rendered":"http:\/\/webninjataylor.com\/library\/?p=3040"},"modified":"2014-06-24T20:56:09","modified_gmt":"2014-06-24T20:56:09","slug":"javascript-partials","status":"publish","type":"post","link":"https:\/\/webninjataylor.com\/library\/javascript-partials\/","title":{"rendered":"JavaScript Partials"},"content":{"rendered":"<p>Gratuitously copied from <a href=\"http:\/\/ejohn.org\/blog\/partial-functions-in-javascript\/\" target=\"_blank\">John Resig&#8217;s blog<\/a>&#8230;<\/p>\n<p>Partially applying a function is a technique in which you can pre-fill-in arguments to a function before it is ever executed. In effect, partially applying a function returns a new function which you can call&#8230;<\/p>\n<pre>String.prototype.csv = String.prototype.split.partial(\/,\\s*\/);\r\nvar results = \"John, Resig, Boston\".csv();\r\nalert( (results[1] == \"Resig\") + \" The text values were split properly\" );\r\n<\/pre>\n<p>In the above case we\u2019ve taken a common function \u2013 a String\u2019s .split() method \u2013 and have pre-filled-in the regular expression upon which to split. The result is a new function, .csv() that we can call at any point to convert a list of comma-separated values into an array.<\/p>\n<h2>Resources<\/h2>\n<ul>\n<li><a href=\"http:\/\/ejohn.org\/blog\/partial-functions-in-javascript\/\" target=\"_blank\">John Resig &#8211; Partial Application in JavaScript<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Gratuitously copied from John Resig&#8217;s blog&#8230; Partially applying a function is a technique in which you can pre-fill-in arguments to a function before it is ever executed. In effect, partially applying a function returns a new function which you can call&#8230; String.prototype.csv = String.prototype.split.partial(\/,\\s*\/); var results = &#8220;John, Resig, Boston&#8221;.csv(); alert( (results[1] == &#8220;Resig&#8221;) + [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[144],"tags":[9],"class_list":["post-3040","post","type-post","status-publish","format-standard","hentry","category-web-shots","tag-javascript"],"_links":{"self":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/comments?post=3040"}],"version-history":[{"count":4,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3040\/revisions"}],"predecessor-version":[{"id":3329,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3040\/revisions\/3329"}],"wp:attachment":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/media?parent=3040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/categories?post=3040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/tags?post=3040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}