【发布时间】:2009-08-07 15:50:14
【问题描述】:
我正在尝试从 JavaScript 中的对象生成一个类。例如:
var Test = {
constructor: function() { document.writeln('test 1'); },
method: function() { document.writeln('test 2'); }
};
var TestImpl = function() { };
TestImpl.prototype.constructor = Test.constructor;
TestImpl.prototype.method = Test.method;
var x = new TestImpl();
x.method();
但这不起作用:它只会写'test 2'(无论出于何种原因,构造函数都没有正确定义)。为什么?
【问题讨论】:
标签: javascript class object