我正在尝试一段时间来切换对象的构造函数而我失败了.继续代码将显示我需要的示例.谢谢.
<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>
Run Code Online (Sandbox Code Playgroud) javascript ×1