Code Monkey home page Code Monkey logo

Comments (7)

ClimbsRocks avatar ClimbsRocks commented on July 23, 2024

it's freaking ugly, but something like this might work:
http://stackoverflow.com/a/1009988/3823857

we could possibly modify it to handle multiple invocations in the same function by looking at line number, kind of like the console does?!

from console.label.

ClimbsRocks avatar ClimbsRocks commented on July 23, 2024

still looking close to impossible, but this gives some hope:
http://stackoverflow.com/a/10276296/3823857

from console.label.

ClimbsRocks avatar ClimbsRocks commented on July 23, 2024

ok, taking a different tack:
find the line number this was called from.
then use one of the tricks above to turn the calling function into a string
use the line number to figure out what line in that string it was invoked from
then use a basic regexp within that line to find "console.label(", and take whatever's inside the parens.

i'm not sure if getting the line number is the global line number, or the line number within that function.
either way, worth investigating:
http://stackoverflow.com/a/3806596/3823857
http://stackoverflow.com/questions/14172455/get-name-and-line-of-calling-function-in-node-js

caveat: we might have to handle this differently if it's in the global scope.

from console.label.

ClimbsRocks avatar ClimbsRocks commented on July 23, 2024

this looks super promising!!
https://github.com/stacktracejs/stacktrace.js

from console.label.

ClimbsRocks avatar ClimbsRocks commented on July 23, 2024

oh my gosh, yes, this looks soooo good:
https://www.stacktracejs.com/

from console.label.

ans-4175 avatar ans-4175 commented on July 23, 2024

Actually you can do this?

const myVar = 'Hello'
Object.keys({myVar})[0]

// returns "myVar"

Do you want me to implement it @ClimbsRocks ?

from console.label.

ClimbsRocks avatar ClimbsRocks commented on July 23, 2024

Omg, brilliant- yes please, @ans-4175 ! That's a much cleaner implementation than I had in mind.

from console.label.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.