{"id":1326,"date":"2022-08-30T15:15:36","date_gmt":"2022-08-30T15:15:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/setting-prototype-for-object-literal-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:36","modified_gmt":"2022-08-30T15:15:36","slug":"setting-prototype-for-object-literal-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/setting-prototype-for-object-literal-collection-of-common-programming-errors\/","title":{"rendered":"Setting prototype for Object Literal-Collection of common programming errors"},"content":{"rendered":"<p>The prototype property is usually present in a Function object. This prototype should be an object, and this object is used to define the properties of an object created with a constructor.<\/p>\n<pre><code>\/\/ Plain object, no prototype property here.\nvar plainObject = {one: 1, two: 2};\n\n\/\/ Constructor, a prototype property will be created by default\nvar someConstruct = function() {\n\n  \/\/ Constructor property\n  someConstruct.constructProp = \"Some value\";\n\n  \/\/ Constructor's prototype method\n  someConstruct.prototype.hello = function() {\n    return \"Hello world!\";\n  }\n};\n\n\/\/ Another constructor's prototype method\nsomeConstruct.prototype.usefulMethod = function() {\n  return \"Useful string\";\n}\n\nvar someInstance = new someConstruct();\nconsole.log(someInstance.hello()); \/\/ =&gt; Hello world!\nconsole.log(someInstance.usefulMethod()); \/\/ =&gt; Useful string\n\nconsole.log(someConstruct.constructProp); \/\/ =&gt; Some value\nconsole.log(someConstruct.prototype); \/\/ =&gt; {usefulMethod: function, hello: function}\n\nconsole.log(plainObject.prototype); \/\/ =&gt; undefined\n<\/code><\/pre>\n<p>So, plain objects have no prototypes. Functions which work as constructors do have prototypes. These prototypes are used to fill an instance created with each construct.<\/p>\n<p>Hope that helps \ud83d\ude42<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:17:00. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>The prototype property is usually present in a Function object. This prototype should be an object, and this object is used to define the properties of an object created with a constructor. \/\/ Plain object, no prototype property here. var plainObject = {one: 1, two: 2}; \/\/ Constructor, a prototype property will be created by [&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-1326","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1326","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=1326"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1326\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}