Currently in the process of developing a JavaScript animation library of significant size, I am contemplating adding debugging code to it. A simple check like this could be implemented:
if(myLib.debugger){
console.warn('warning message');
}
However, running this check multiple times per second could potentially lead to performance issues. The situation would exacerbate with additional checks throughout the code.
I am considering whether it is feasible to enable the debugger onload and modify code from something like this:
//debugger if(!this.name) console.warn('No name provided');
to:
if(!this.name) console.warn('No name provided');
By keeping the code commented when not enabled and uncommented when needed, any potential performance concerns can be mitigated. Is there a way to achieve this using regular expressions on the entire script if loaded through ajax? I am aiming to avoid maintaining two versions of the same code - one for debugging and another without it.
The focus here is on functionality rather than cross-browser compatibility (primarily targeting newer browsers). Nonetheless, achieving this would be highly beneficial if possible.
Any insights or suggestions on this matter would be highly valued.