访问 javascript 类中的变量而不实例化它是不好的做法吗?
例如:
var Test = function(){
this.tests.push("Something");
}
Test.prototype.tests = [];
var test = new Test();
console.log(Test.prototype.tests); //Is this okay to do? Obviously I can use test.test here, but this is a poor example of why I am wanting to do this; it merely shows my question.
我遇到了一个实例,我只有一个 id,我想使用该类为我获取正确的实例:Test.prototype.getByID(id);
但我想确保这样做是正确的。