5 ms·
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.someMetho
by M4v3R 13y ago
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.
- nccong 13y agoGood point. It's a quick way to debug/experiment.
- GeneralMayhem 13y agoMy 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.