我有一个名为foo
的对象:
function Foo(){
this.conceal = function(){ ... };
};
以及一个名为toggleView
的方法,它在每个实例上遍历foo
的集合并调用conceal()
方法:
function toggleView(foos){
for(a in foos){
foos[a].conceal();
}
}
当然,foos[a].conceal();
会返回:隐藏不是一种功能
答案 0 :(得分:1)
function Foo(){
this.conceal = function( item ) {
console.log(item); // "a" "b" "c"
};
};
function toggleView(foos) {
var myFoo = new Foo(); // Create new instance (here or outside this fn)
for(a in foos){
myFoo.conceal(foos[a]); // use your instance and pass as items arg. reference
}
}
toggleView(["a","b","c"]);

示例toggleView
Foo
function Foo(){
this.conceal = function( item ) {
console.log(item); // "a" "b" "c"
};
}
Foo.prototype.toggleView = function(foos) {
for(a in foos){
this.conceal(foos[a]); // invoke .conceal Method using `this` reference
}
}
var myFoo = new Foo(); // Create new instance
myFoo.toggleView(["a","b","c"]);

答案 1 :(得分:0)
你应该在某个时候调用函数Foo,以便隐藏成为“函数”。