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/
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/
You can, but I think it's non-standard and therefore not supported by every browser:
a.__proto__ = b.prototype;