2013-11-01 37 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 –

相關問題