javascript trivial tricks

Recently I’ve been developing an app that relies heavily on socket.io to do it’s work. So when one needs to debug such an app there is an option to:

write all at once and hope it works do little changes etc. something like waterfall model 🙂

or

reload, click trough your use case and inspect over and over

or

hack something up to enable messing around with code with more speed.

people that talk about performance say that if search time of google drops then people tend to search less.

So maybe hacking something up will in the end give better code 😀

One can fire up console in chrome devtools and do something like this:

if(!window.callbackSet){

    socket.on(‘news’,function(data){window.callback(data);});

}

window.callbackSet=1;

socket.emit(‘exec’,{});

window.callback=function (data){

    debugger; // breakpoint

}

Then listener will be set on news event only first time, while callback function can be changed over and over. Devtools console enables multi line editing with Shift+Enter

This is a trivial trick but it changed the way I develop my socket.io app since app has to do bunch of work parsing the response it offers speedy debuggable solution. You can set a breakpoint if you put “debugger;” somewhere. Now I develop entire socket.io feature in console and then just integrate it in app.

also on setting comments :

function(){

some code here;

//*/ //this line changes nothing just stands here

}

but now if you add /* like this everything is commented out 😀

function(){

/*

some code here;

//*/ //this line changes nothing just stands here

}

Leave a Comment