{"id":1687,"date":"2011-03-25T18:43:00","date_gmt":"2011-03-25T18:43:00","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=1687"},"modified":"2011-12-24T18:43:11","modified_gmt":"2011-12-24T18:43:11","slug":"creating-javascript-objects-using-new-the-pros-and-cons","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=1687","title":{"rendered":"Creating Javascript Objects using new &#8211; the pros and cons"},"content":{"rendered":"<p>There are a number of pros and cons regarding this practice, and they are debated on StackOverflow <a href=\"http:\/\/stackoverflow.com\/questions\/383402\/is-javascript-s-new-keyword-considered-harmful\"><strong>here<\/strong><\/a>. A w3schools tutorial on it may be found <a href=\"http:\/\/www.w3schools.com\/js\/js_objects.asp\"><strong>here<\/strong><\/a>.<\/p>\n<p>I have used this e.g. <a href=\"http:\/\/salientsoft.co.uk\/?p=1671\"><strong>here<\/strong><\/a>, following the lead of the Primefaces dialog.js. A downside is that your code fails if you forget the <em>new<\/em> and just call the function instead. However, this can be detected and an error thrown as per the StackOverflow post. In my case, the thrown error was not easily detected so I elected to pop an alert as well.<\/p>\n<p>I do not discuss the issue further here \u2013 just follow the links and you will find plenty of information on it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a number of pros and cons regarding this practice, and they are debated on StackOverflow here. A w3schools tutorial on it may be found here. I have used this e.g. here, following the lead of the Primefaces dialog.js. A downside is that your code fails if you forget the new and just call [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[147],"tags":[89,16,15],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1687"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1687"}],"version-history":[{"count":1,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1687\/revisions"}],"predecessor-version":[{"id":1692,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1687\/revisions\/1692"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}