【发布时间】:2011-06-03 03:03:56
【问题描述】:
我一直在努力加深对 javascript 命名空间和原型继承的理解,但我遇到了一个问题。
我正在处理的代码示例:
var namespace = {
ex1: function () { },
ex2: function () {
this.exvar1 = 0,
this.exvar2 = 0;
}
}
namespace.ex1.prototype = {
method1: function () {
},
method2: function () {
}
};
namespace.ex2.prototype = {
method1: function () {
alert("ex2.method1" + typeof this.method1);
},
method2: function () {
alert("ex2.method2" + typeof this.method2);
}
};
如果我尝试通过以下方式调用方法:
namespace.ex2.method1();
我发现 namespace.ex2.method1 不是函数。
我错过了什么?
【问题讨论】:
标签: javascript namespaces