Welcome...



...All those moments will be lost in time, like tears in rain....

- soliloquy from Blade Runner


Bits and bytes do get lost, awash in the rain of data flow that is Internet. They slip away from us, never to found again... some of them will be captured here, many more will not... like tears in rain...



Wednesday, March 20, 2013

Voyager 1 left Solar system for good...

 Looks like it's official now - Voyager 1 crossed the edge of Solar system! For somebody who still remembers Carl Sagan's "Cosmos" that's exciting news. I wonder how long it will keep sending...
Go Voyager Go!

Wednesday, March 6, 2013

This and that in JavaScript

 This and that in JavaScript - or self as I've seen it, is just a workaround for the fact that in JavaScript, inner function "this" is not behaving like "this" from the outer function, it points to the window object.. Yes, it's a bug, and it will be fixed in ECMA5.

To preserve outer function "this", putting "this" into local variable ("that" or "self") will allow transfer of variable from outer function to be used, by using closures.

Closure mechanism - an inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.

Something like this:

<!DOCTYPE html><html lang="en">
<head></head>
<body>
<script>
 var myObject = 
{
  myProperty:'Some text here'
  myMethod:function() 
  {
   var that = this; //reference to myObject in myMethod scope 
   var innerFunction function() { // inner one
           console.log(that.myProperty); //logs 'Some text here'
           console.log(this); // logs window object to show what will happen if we don't store this into that
        }();
    }
}
myObject.myMethod(); // invoke myMethod

</script>
</body>
</html>

Debugging client side script

I was trying to debug client side code and was getting those "Breakpoint will not be hit" messages. Turn out that to allow debugging of the client side script, you need to Attach debugger to the process but before you actually do that,  click Select button on the top of the list of processes. If it on automatic, change it to Script.
 That functionality goes back to Visual Studio 2008 and it's still there in VS 2012.
 There are other ways too - debugger; in javascript code, or using Client debugging in IE or Firefox (or Chrome), but it's nice not to have to do anything extra but use VS when you want to attach to the process anyways.