我可以像这样在 JavaScript 中定义一个类:
var appender = function (elements, func) {
this.Prop = something;
staticProp = something_else;
};
我对吗?那么,我怎样才能在这个类中创建一个静态字段呢?以及如何访问课堂内的该字段?我的意思是我想要一个在类的所有实例之间共享的字段。
var ap1 = new appender();
var ap2 = new appender();
ap1.Prop = something1;
ap2.Prop = something2;
var t = ap1.Prop == ap2.Prop; // true
ap1.staticProp = something_static;
var s = ap2.staticProp = something_static; // I want to this returns true. how can I?