简体   繁体   English

为什么console.log在.each内部不起作用?

[英]why is console.log not working inside .each?

I tried doing the following: 我尝试执行以下操作:

$('.not-following').each(function(i, obj) { 
      console.log('test');
});

for some reason it keeps on printing the obj instead of test. 由于某种原因,它会继续打印obj而不是测试。 Any reason why this is? 有什么原因吗? I tried running this on here 我尝试在这里运行

They overwritten console 他们覆盖了控制台

> console.log.toString()
"function (){}"

It isn't printing the object instead, what you are seeing is the jQuery (array of nodes) that the .each() function returns. 它不是打印对象,而是您看到的是.each()函数返回的jQuery(节点数组.each()

The reason console.log() is not working is that Twitter has replaced the method with an empty function, as console.log in production is considered bad practice. console.log()无法正常工作的原因是Twitter已用空函数替换了该方法,因为生产环境中的console.log被认为是不良做法。

If you need to access console.log you can delete the 'overridden' version that the Twitter developers have written by invoking: 如果您需要访问console.log ,则可以通过调用以下操作来删除Twitter开发人员编写的“覆盖”版本:

delete console.log

The will default console.log back to it's original function. 将默认的console.log返回到其原始功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM