Saturday, July 4, 2015

typeof in JavaScript

  1. var x = function(){};
    alert(typeof x);

       ...is going to bubble up: function
     
  2. var x = 33;
    alert(typeof x);

       ...is going to bubble up: number
     
  3. var x = "Hello World.";
    alert(typeof x);

       ...is going to bubble up: string
     
  4. var x = {
       y: "why not?"
    }
    alert(typeof x);

       ...is going to bubble up: object
     
  5. etc.

Thursday, July 2, 2015

Did you know that you may add a NOT NULL column to an existing table that has rows in it with T-SQL?

You have to give a default value and the constraint for it has to be given at the moment the column is added like so:

ALTER Table My_Corny_Table
ADD The_Date DateTime NOT NULL
CONSTRAINT DF_My_Corny_Table_The_Date DEFAULT GETDATE()

_aspxCancelBubble in DevExpress 13

...is not an event in version 15! Pull this out of your JavaScript or it will blow up.

When a build does not restore NuGet packages....

Try pulling everything down out of source control fresh into a fresh folder while first destroying the root folder of the app. That ".nuget" folder needs to go away in the cleansing with everything else.

Wednesday, July 1, 2015

the scope of this in JavaScript

Kyle Simpson's book this & OBJECT PROTOTYPES lists four varieties of bindings for this:

  1. Default Binding just looks up the call-stack for the call-site. One step up the history of calls from the spot at hand is where this is defined. As the name implies, this is the default.
    function sigourneyWeaver() {
       alert("The computer says: " + this.message);
    }
    var message = "Hello World";
    sigourneyWeaver();

     
  2. Implicit Binding has one fishing for this.whatever at an object's properties.
    function sigourneyWeaver() {
       alert("The computer says: " + this.message);
    }
    var computer = {
       message: "Hello World",
       operator: sigourneyWeaver
    }
    computer.operator();

     
  3. Explicit Binding is the .call stuff.
    function sigourneyWeaver() {
       alert("The computer says: " + this.message);
    }
    var computer = {
       message: "Hello World"
    }
    sigourneyWeaver.call(computer);

     
  4. new Binding lets you sidestep the usual truth that when using this in a function, you are not referring to the scope of the function itself.
    function sigourneyWeaver(message) {
       this.reiteration = "The computer says: " + message;
    }
    var noomiRapace = new sigourneyWeaver("Hello World");
    alert(noomiRapace.reiteration);

     

The third of the four, Explicit Binding, is the most interesting. When a primative is handed into a function, behind the scenes it is boxed. The boxing allows for the primative to be created as if newed up. A string is handed to the function such that makes it into the function as if assigned by a = new String("Hello World"); approach. Such affects this like so:

function sigourneyWeaver() {
   alert("The computer says: " + this);
}
sigourneyWeaver.call("Hello World");

 
 

In the concept of Hard Binding the function called with Explicit Binding is always called from a wrapper function to which variables to be passed on are handed in. This keeps the scope of this from behaving unexpectedly. One interesting thing about the example in the book is that it revealed to me that functions have an "arguments" variable which is an array of all variables handed into the function even if or without regard to if they are not defined at function's signature. Observe:

function sigourneyWeaver() {
   alert("The computer says: " + this);
}
function rickMoranis() {
   sigourneyWeaver.call(arguments[0]);
}
rickMoranis("Hello World");

 
 

Now imagine the protected function was swappable at the wrapping function like so:

function sigourneyWeaver() {
   alert("The computer says: " + this);
}
function rickMoranis(gateKeeper, message) {
   gateKeeper.call(message);
}
rickMoranis(sigourneyWeaver, "Hello World");

 
 

Alright, because this is a common pattern for Explicit/Hard Binding JavaScript makes the code immediately above a bit easier to repeat with .bind like so:

function sigourneyWeaver() {
   alert("The computer says: " + this);
}
var rickMoranis = sigourneyWeaver.bind("Hello World");
rickMoranis();

more random notes of sprucing up one's Windows environments

  1. open "Disk Defragmenter" in Windows 7 by typing "Disk Defragmenter" at the start menu and then click the "Configure schedule..." button to set a schedule
  2. when installing from an .iso to a VMware VM you may click on the CD option at the left navigation in VMware and there will be an option ("Use ISO image file:") for picking an .iso file at your main machine outside of your VMs
  3. You can't add hard disk space to a VMware VM while it's running. You need to power it down first. Then, click the Hard Disk option at the left nav and pick "Utilities" to add space or "Add" to add a new partition. If you add a new partition, when you bring your VM back up you need to (assuming Windows Server 2008 R2) open Server Manager and drill down to Disk Management below Storage. Right-click on the grey title of the partition and pick "Online" and then right-click again and pick "Initialize Disk" and finally right-click in the white of the horizontal slat of the drive listing and pick: "New Simple Volume"

When taking a snapshot of a VM in VMware it may be best to have the VM powered off.

It was pointed out to me today that not doing so captures a bunch of other state and balloons the footprint of the snapshot and increases the likelihood of something going South. A snapshot I restored that was taken when the VM was up was sickly at work today and spun and spun while trying to install Windows updates upon a restart.