假设我有以下模块
var TestModule = (function () {
var myTestIndex;
var module = function(testIndex) {
myTestIndex = testIndex;
alertMyIndex();
};
module.prototype = {
constructor: module,
alertMyIndex: function () {
alertMyIndex();
}
};
function alertMyIndex() {
alert(myTestIndex);
}
return module;
}());
我声明了它的 3 个实例
var test1 = new TestModule(1);
var test2 = new TestModule(2);
var test3 = new TestModule(3);
如何得到
test1.alertMyIndex();
显示 1 而不是 3?