{"id":4056,"date":"2014-03-30T07:22:09","date_gmt":"2014-03-30T07:22:09","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-create-a-function-or-object-property-name-in-runtime-via-string-concatenation-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:22:09","modified_gmt":"2014-03-30T07:22:09","slug":"how-to-create-a-function-or-object-property-name-in-runtime-via-string-concatenation-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-create-a-function-or-object-property-name-in-runtime-via-string-concatenation-collection-of-common-programming-errors\/","title":{"rendered":"How to create a function or object property name in runtime via string concatenation?-Collection of common programming errors"},"content":{"rendered":"<p>I create portlets and there can be many instance of a portlet on a page, so that the functions and dom elements must be identified, AKA they must start with a particular namespace.<\/p>\n<p>so that in some cases, I have to have my JS in a JSP page and cannot move it to a separate file, it is very inconvenient and hard to maintain.<\/p>\n<p>a javascript in a JSP<\/p>\n<pre><code>var validator = new A.FormValidator({\n        boundingBox: document.orderForm,\n\n        validateOnBlur: true,\n        validateOnInput: false,\n\n        rules: {\n\n            significanceLevel: {\n                digits: true                \n            },\n\n            languageFrom: {\n                required: true,\n                notEqualTo: '#languageTo'\n            },\n\n            languageTo: {\n                required: true,\n                notEqualTo: '#languageFrom'\n            }\n}\n......\n<\/code><\/pre>\n<p>From <code>significanceLevel<\/code> JSP generates <code>_my_namespace_significanceLevel:<\/code> . Even if I pass myNamespace (from a JS in JSP &#8211; namespaces resolved on serverside) into a constructor, I cannot create myNamespace + &#8216;methodName&#8217; in runtime<\/p>\n<p>Namespace is only known on serverSide. So that one JS always has to be in a JSP page so that is resolved and all other JS objects have it accessible via constructor parameter for instance.<\/p>\n<p>this is one workaround, but it cannot be used in many cases :<\/p>\n<pre><code>window[instance._method] = function() {\n    instance.fileAddError.apply(instance, arguments);\n};\n<\/code><\/pre>\n<p>where the name of _method was concatenated from string literals<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I create portlets and there can be many instance of a portlet on a page, so that the functions and dom elements must be identified, AKA they must start with a particular namespace. so that in some cases, I have to have my JS in a JSP page and cannot move it to a separate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4056","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4056"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4056\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}