Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I used the prototype mechanism several times when debugging a script that I couldn't easily change source code for. I just typed:

SomeClass.prototype.someMethod

Which outputs the methods source. Then you can add some debug code like console.log(xxx) or even fix a simple bug, copy the whole thing and set it again:

SomeClass.prototype.someMethod = function ...

Voila! Hot code push without an IDE. While that's obviously not ideal, it certainly works in some cases.



My favorite trick along those lines:

  var cache = SomeClass.prototype.someMethod;
  SomeClass.prototype.someMethod = function () {
    debugger; // or `throw "stacktrace"`
    cache.apply(this, arguments)
  }
Inserts a stack trace right in the middle of executing someone else's code, which is nice for tracking down why/when that function gets called if documentation is poor, without changing functionality.


Good point. It's a quick way to debug/experiment.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: