Delegates in Javascript
I've recently been doing javascript coding again. Being the object bigot that I am, everything that interacts with a DOM element gets wrapped in an object that becomes responsible for that element's behavior. Well, then i tried to move all the event handler code from the procedural side to the object side and things broke, and hard.
At first I was confused why it wouldn't call my this._InternalMethod inside my event handler. Then I remembered that i've been spoiled by the CLR and that I was dealing with plain old function pointers, not delegates.
While the Atlas framework provides delegate functionality (along with a lot of other useful things), this was not for a .NET 2.0 project and I didn't want to graft the Atlas clientside onto it as a dependency. But knowing that Atlas does delegates, i knew it was possible.. but how?
I found the answer in this article which basically uses closures in javascript to allow the persistent of the object context in event handlers.
So basically to create an event handler that maintains its object context do this:
function MyObject = function(name)
{
this._name = name;
var _this = this;
this.MyEventHandler = function()
{
alert("My name is "+_this._name;
}
}
Great. Now I can avoid all procedural code and just have my object subscribe themselves to element and document events and handle them in their own context
It's getting harder to upgrade that TiVo
When we got a Humax Series 2 TiVo (to replace our faithful Series 1) it almost immediately started making clicking noises that usually signify the imminent death of disk. We figured, if we sent it in, they'd just see it working and send it back. So we started the TiVo deathwatch. 2 years later it still hadn't died, but now, about once a week, the clicking is followed by the machine rebooting. The warranty expired a while back, so time to replace the the disk.
Being a Series 2, I decided to use a disk larger than 137GB. Quick trip to Fry's and I had a shiny 200GB disk. Now, it's been a while since I put the 120GB in the trusty Series 1 (which is still running strong and better than the Series 2), so my other PCs have gone through some changes. Turns out that all my new machines use SATA and have only one ATA port. And the DVD is hooked to that port, which leaves only one more available connection.
Right, you need at least 3 -- CD, source HD, target HD. Ok, no problem, I have an old box that's the home file server. That one not only has two ATA, but it also has a PCI card with another 2 ATAs (for large disk support). A couple of minutes later, I booted into the weaknees CD and all seemed fine. The boot messages showed all disks properly set up. But apparently the setup that weaknees used did not have any devices above /dev/hdd. So my disks hooked to /dev/hdf and /dev/hdh were not accessible. And i couldn't use the /dev/hd(a)-(d) because my disk was 200GB and was not recognized as such with the onboard ports.
Fortunately, the server itself runs Fedora, so i copied the mfs tools from the CD onto the HD and booted into Fedora with the tivo disks attached. Everything worked out fine and now i've got a potential 219 hours on tap!
But I guess the lesson is that ATA is going away, so what I used to take for granted is no longer there when the tivo tweaking calls.