{"id":161,"date":"2013-03-18T20:27:32","date_gmt":"2013-03-18T20:27:32","guid":{"rendered":"http:\/\/www.webninjataylor.com\/library\/?p=161"},"modified":"2014-06-24T21:42:34","modified_gmt":"2014-06-24T21:42:34","slug":"javascript-creating-your-own-global-namespace","status":"publish","type":"post","link":"https:\/\/webninjataylor.com\/library\/javascript-creating-your-own-global-namespace\/","title":{"rendered":"JavaScript: Creating Your Own Global Namespace"},"content":{"rendered":"<p>Start with a global object variable declaration and extend that object with properties&#8230;<\/p>\n<pre>var wnt = {}; \/\/Start with the global declaration\r\nwnt.util = {}; \/\/Add a new level (if desired)\r\nwnt.util.urlparameter = function(name) {\r\n    return decodeURI(\r\n        (RegExp(name + \u2018=\u2019 + \u2018(.+?)(&amp;|$)\u2019).exec(location.search)||[,null])[1]\r\n    );\r\n}; \/\/Turn a level into a method\r\nalert(eval(wnt.util.urlparameter(\u2018page\u2019))-1); \/\/assumes URL ends with ?page=n and subtracts one so it can be used in conjunction with $.eq() to count in a 0-based array.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Start with a global object variable declaration and extend that object with properties&#8230; var wnt = {}; \/\/Start with the global declaration wnt.util = {}; \/\/Add a new level (if desired) wnt.util.urlparameter = function(name) { return decodeURI( (RegExp(name + \u2018=\u2019 + \u2018(.+?)(&amp;|$)\u2019).exec(location.search)||[,null])[1] ); }; \/\/Turn a level into a method alert(eval(wnt.util.urlparameter(\u2018page\u2019))-1); \/\/assumes URL ends with [&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-161","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\/161","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=161"}],"version-history":[{"count":4,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":3387,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/161\/revisions\/3387"}],"wp:attachment":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}