{"id":1190,"date":"2022-08-30T15:13:53","date_gmt":"2022-08-30T15:13:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/how-to-assign-a-prototype-to-an-already-constructed-object-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:13:53","modified_gmt":"2022-08-30T15:13:53","slug":"how-to-assign-a-prototype-to-an-already-constructed-object-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-assign-a-prototype-to-an-already-constructed-object-collection-of-common-programming-errors\/","title":{"rendered":"How to assign a prototype to an already constructed object?-Collection of common programming errors"},"content":{"rendered":"<p>The following code alerts &#8216;undefined.&#8217; Can I make it alert &#8216;2&#8217; without changing the first three lines?<\/p>\n<pre><code>var b = function(){}\nb.prototype.c = 2\nvar a = {}\n\na.constructor = b\nalert(a.c)\n<\/code><\/pre>\n<p>fiddle: http:\/\/jsfiddle.net\/FHLgR\/4\/<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:40:10. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>The following code alerts &#8216;undefined.&#8217; Can I make it alert &#8216;2&#8217; without changing the first three lines? var b = function(){} b.prototype.c = 2 var a = {} a.constructor = b alert(a.c) fiddle: http:\/\/jsfiddle.net\/FHLgR\/4\/ Originally posted 2013-11-09 23:40:10.<\/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-1190","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1190","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=1190"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1190\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}