我正在试着做一个函数,每个赋值都有一个实例变量,例如带有实例变量的javascript函数
function Sample() {
Sample.myInstanceVar = true; // <--- This var should be instance-specific
}
var a = Sample;
console.log(a.myInstanceVar); // should return undefined and it does
a.apply(this);
var b = Sample;
console.log(b.myInstanceVar); // i would like to get this one to return undefined here, but it returns true;
希望你明白了吧:-)
UPDATE:>
我不感兴趣的样品是因为它的功能我正在引用的实例。我要样品有某种变量或实例的特定于范围/背景我在参考样品。
你完全误解了实例。 (你实际上没有) – SLaks
'var a = Sample;'是对Sample()函数的引用,而不是实例。 – crush
你想用这个完成什么? – BBog