2013-11-01 40 views
1

我试着做以下几点:为什么console.log不能在.each里面工作?

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

由于某种原因,它使上打印obj的,而不是测试。这是为什么?我试着here

+10

很可能是因为您的选择器没有选择任何东西。 'console.log($('。not-following')。length)' –

+2

你可以发布一个jsfiddle链接或其他东西,你的url dosent似乎可以工作 – neoeahit

+1

并在这里发布你的HTML **。 – j08691

回答

10

运行此它们覆盖控制台

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

那么这是什么意思?我不能使用控制台? – adit

+2

作为进一步的证明(和解决方案),运行'delete console.log'并重试。这应该吹走冒名顶替者console.log,并揭露真实的。 – apsillers

+0

相关问题:http://stackoverflow.com/questions/12611803/why-is-console-log-an-empty-function-on-some-sites-in-chrome – aug

4

它不打印的对象,而不是,你看到的是jQuery的(节点阵列)的.each()函数返回。

console.log()不起作用的原因是Twitter已经用空函数替换了该方法,因为console.log在生产中被认为是不好的做法。

如果您需要访问console.log可以删除Twitter的开发人员通过调用写的“重写”的版本:

delete console.log 

的将默认CONSOLE.LOG回到它的原始功能。

+0

不错,带@apsillers评论并将其添加到您的答案。 ;) – epascarello

+2

你指的是哪条评论? (编辑)对不起,我没有看到其他答案的评论。 – azz

+0

@DerFlatulator:This one:http://stackoverflow.com/questions/19728824/why-is-console-log-not-working-inside-each#comment29311186_19728924 :-D –

相关问题