如果你希望你的构造函数是公开的,你可以使用这个解决方法:
(function(global){
function kindOfPrivateFunction(thing){
//Do something with thing
}
global.Thing = function(a, b) {
this.prop1 = a;
this.prop2 = b;
knindOfPrivateFunction(this);
};
global.Thing.publicFunction = function() { };
})(this);
或者,如果您不想让 resharper 抱怨 "ThisInGlobalContext" :
(function(){
function kindOfPrivateFunction(thing){
//Do something with thing
}
this.Thing = function(a, b) {
this.prop1 = a;
this.prop2 = b;
knindOfPrivateFunction(this);
};
this.Thing.publicFunction = function() { };
})();
编辑
考虑到您的类必须是本地的,您可以使用本地对象来“存储”本地构造函数。但这实际上只是关闭 Resharper 的一种技巧......
(function(){
var local = {};
function kindOfPrivateFunction(thing){
//Do something with thing
}
local.Thing = function(a, b) {
this.prop1 = a;
this.prop2 = b;
knindOfPrivateFunction(this);
};
local.Thing.prototype.publicFunction = function() { };
var instance = new local.Thing(1, 2);
})();