当创建多个 tempobj 实例时,下面的代码是否会创建函数 fun1 的多个实例?我知道为每个对象创建单独的 fun2 实例。我需要知道 fun1 是否也会发生同样的情况。
function tempobj(){
var fun1 = function(){
//do something;
}
this.fun2 = function(){
//do something;
}
}
var obj1 = new tempobj();
var obj2 = new tempobj();
var obj3 = new tempobj();
最佳答案
答案是肯定的,您每次创建对象时都定义了 fun1。
关于javascript - 在javascript中为类中的私有(private)函数创建实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10087142/