You need to do something like console.log() in chrome, when the row number is displayed next to where this method was called.

    3 answers 3

    If I understand you correctly, try this (chrome only):

     console.line = function (offset){ var halt; try { halt(); } catch( error ){ var info = error.stack.split('\n')[2 + ~~offset].match(/at\s+([^\s]+)\s+\((.+):(\d+):/); console.info('"'+info[1]+'": line '+info[3]+' in '+info[2]); } }; console.spy = function (ctx, name){ var fn = ctx[name]; ctx[name] = function (){ console.line(1); return fn.apply(ctx, arguments); }; }; // Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΌΠ΅Ρ‚ΠΎΠ΄Π°, Π½ΠΎΠΌΠ΅Ρ€ строки ΠΈ имя Ρ„Π°ΠΉΠ»Π° console.line(); // Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΈ Π½ΠΎΠΌΠ΅Ρ€ строки ΠΌΠ΅Ρ‚ΠΎΠ΄Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π²Ρ‹Π·Π²Π°Π» эту Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ console.spy(document, 'addEventListener'); 

    Example - http://jsfiddle.net/qpqF9/

      I think the easiest option is to throw an exception, and then parse the stacktrace:

       console.getLine = function() { function getError() { try { throw new Error() } catch(err) { return err } } return parseInt(getError().stack.replace(/[\(|\)]/g, '').match(/:(\d+)(:\d+)?[\n]?$/g)[0].substr(1)); } alert(console.getLine()); 

      Demo: http://jsfiddle.net/kLgMC/4/ (works in Chrome, Opera, Firefox and IE)

       myLog((new Error).stack); function myLog(stack){ // ..parse Stack // return parse Stack }