我一直在努力深入了解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 不是一个函数。我错过了什么吗?