How to assign a prototype to an already constructed object?-Collection of common programming errors
The following code alerts ‘undefined.’ Can I make it alert ‘2’ 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.