【发布时间】:2013-06-16 03:24:59
【问题描述】:
我正在深入研究 Javascript,并学习构造方法的工作原理。
在下面的代码中,我希望我能够覆盖对象的构造函数,以便新创建的实例将使用新的构造函数。但是,我似乎无法让新实例使用新的构造函数。
任何有关正在发生的事情的见解将不胜感激!
function constructorQuestion() {
alert("this is the original constructor");
};
c = new constructorQuestion();
constructorQuestion.constructor = function() { alert("new constructor");}
howComeConstructorHasNotChanged = new constructorQuestion();
【问题讨论】:
标签: javascript object constructor