我已经在Stack Overflow,Google和Google Code中搜索了两天,但都找不到答案。所以听到...
我有一个与此类似的JS对象:
var profile1 = {
one: "1",
two: "2"
}
var profile2 = {
one: "3",
two: "4"
}
function runLoop () {
console.log(this.one);
}
profile1.loop = runLoop;
profile2.loop = runLoop;
profile1.loop();
因此,在这种情况下,profile1.loop()可以正常运行,并返回字符串值“ 1”。但是,如果我尝试从Chrome或FF的控制台中运行它,则仍会返回“ 1”,但会发出一条消息“ undefined”。
可以解决这个问题还是我在这里追尾?如果SO上存在此问题的答案,请发布。
最佳答案
我想说您是在追尾,因为那里没有什么可修复的。如果您不想在控制台中看到“未定义”一词,则可以从该函数中返回想要看到的任何内容。
例如
function runLoop() {
console.log(this.one);
return 'loop complete!!!!';
}
> profile1.loop();
1
'loop complete!!!!'
关于javascript - 是否可以删除Chrome和Firefox控制台中的“未定义”调用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7373187/