I am trying for a while to switch constructor for a object and I am failing. Continuing code will show example of what I need. Thanks.
<script type="text/javascript">
function Me(){
this.name = "Dejan";
}
function You(){
this.name = "Ivan";
}
Me.prototype.constructor = You;
somebody = new Me();
alert(somebody.name); // **It gives Dejan, and I am expecting Ivan**
</script>
You can’t change the constructors of an object, you can however change the ‘type’ of the object the constructor returns, with (as in your example)
which would cause new Me()’s to inherit from the object You. However this.name in the Me() function will overshadow the one inherited from you so do something like this: