{"id":7063,"date":"2014-05-19T04:11:19","date_gmt":"2014-05-19T04:11:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/19\/how-to-find-if-a-function-is-inbuilt-function-or-user-defined-collection-of-common-programming-errors\/"},"modified":"2014-05-19T04:11:19","modified_gmt":"2014-05-19T04:11:19","slug":"how-to-find-if-a-function-is-inbuilt-function-or-user-defined-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/19\/how-to-find-if-a-function-is-inbuilt-function-or-user-defined-collection-of-common-programming-errors\/","title":{"rendered":"How to find if a function is inbuilt function or user-defined-Collection of common programming errors"},"content":{"rendered":"<p>One, perhaps naive, approach would be to test whether the function name exists a property of the document:<\/p>\n<pre><code>function newFunction (){\n    return true;\n}\n\nconsole.log('newFunction' in document, 'toString' in document);\n<\/code><\/pre>\n<p>This is, of course, <em>not<\/em> exhaustively tested and does fail if the function is created as an extension of a <code>prototype<\/code>, for example:<\/p>\n<pre><code>function newFunction (){\n    return true;\n}\n\nObject.prototype.newFunctionName = function () {\n    return 10 * 2;\n};\n\nconsole.log('newFunction' in document, 'toString' in document, 'newFunctionName' in document); \/\/ false, true, true\n<\/code><\/pre>\n<p>JS Fiddle demo.<\/p>\n<p>Given that it also fails for <code>'eval' in document<\/code> (in that it returns <code>false<\/code>), then this will, or <em>can<\/em>, only work to identify prototype-methods of the Objects. Which is, at best, an incomplete solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One, perhaps naive, approach would be to test whether the function name exists a property of the document: function newFunction (){ return true; } console.log(&#8216;newFunction&#8217; in document, &#8216;toString&#8217; in document); This is, of course, not exhaustively tested and does fail if the function is created as an extension of a prototype, for example: function newFunction [&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-7063","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7063","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=7063"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7063\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}