Monthly Archives: July 2009

Bipolar: Objects vs. Primatives

Boolean(0) === false
new Boolean(0) == false
new Boolean(0).valueOf() === false
!new Boolean(0) == false
Number(0) === 0
new Number(0) == 0
new Number(0).valueOf() === 0
!new Number(0) == 0

After my initial startle, I remembered that objects are always truish in JavaScript. So an object that has a meaning of false is still truish. Below is the same set of statements with comments:

// cast as boolean
Boolean(0) === false
// a new object with value of false
new Boolean(0) !== false
new Boolean(0) == false
!new Boolean(0) == false
// get the primative value of the object
new Boolean(0).valueOf() === false
// cast as number
Number(0) === 0
// a new number with a value of 0
new Number(0) !== 0
new Number(0) == 0
!new Number(0) == 0
// get the primative value of the object
new Number(0).valueOf() === 0

So I ended up with the following functions:

function isFalsy(o) {
  return (o && o.valueOf ? !o.valueOf() : !o);
}

function isTruish(o) {
  return (o && o.valueOf ? !!o.valueOf() : !!o);
}

Still, it is fun to say that there is a situation where “something == false” and “!something == false”.

Google Plays Poker

2. It’s not too late for Google to enter the OS market. Google is a lot like Apple, they don’t invent things, they “perfect” things. Google did not invent search or email, but they took those to the next level after the markets were quite mature.

3. Google has amazing experience making OS. They’ve built very complex data storage systems to be infinitely scalable and triple redundant. Here is a white paper on the file system component of their storage systems: http://labs.google.com/papers/gfs.html . They must have done some Linux development to get the storage systems so mature. And don’t forget about Android.

4. Google may be targeting netbooks, but look at the larger picture. It seems their long-term goal is really cloud computing. As you mention, Google will encourage and develop the cloud concept, but I think they have much bigger plans for cloud computing. And Netbooks are just a foot in the door–what better way to sell storing data off the computer than on a cheap and puny computer that holds non-professional data and is not designed to be a long-term computer.

Google has an amazing long-term vision and I have a feeling that Chrome OS is not an end in itself, but a vehicle to take their business models to the next level. Google holds a lot of cards it hasn’t revealed.

IE Lost My Node Contents

I get a reference to a node, set the parent’s innerHTML then try to manipulate the node. The node should have all it’s properties and child objects and does in standards-compliant browsers.

Minimal Example:

<div id="outer">
  <p id="inner"><span>old innerHTML</span></p>
</div>

<script type="text/javascript">
var outer = document.getElementById('outer');
var inner = document.getElementById('inner');
outer.innerHTML = 'new innerHTML';
alert(inner && inner.innerHTML ? 
  'The inner node still has innerHTML: ' + inner.innerHTML : 
  'The inner node\'s guts are gone, '
    + 'but .tagName = ' + inner.tagName
);
</script>

Try it yourself.

Did I mention IE is the bane of my existence?

IE Lost My Node Contents

I ran into the most bizarre JavaScript bug that plagues all versions of IE.

I get a reference to a node, set the parent’s innerHTML then try to manipulate the node. The node should have all it’s properties and child objects and does in standards-compliant browsers.

However, in IE, the node retains its attributes but has no children. That’s right, #getElementsByTagName() returns an empty HTMLNodeList. #children? Empty HTMLNodeList. The weirdest thing is that #firstChild still exists, but it is an object with no properties whatsoever.

Minimal Example:

<div id="outer">
  <p id="inner"><span>old innerHTML</span></p>
</div>

<script type="text/javascript">
var outer = document.getElementById('outer');
var inner = document.getElementById('inner');
outer.innerHTML = 'new innerHTML';
alert(inner && inner.innerHTML ? 
  'The inner node still has innerHTML: ' + inner.innerHTML : 
  'The inner node\'s guts are gone, '
    + 'but .tagName = ' + inner.tagName
);
</script>

Try it yourself

.

Did I mention IE is the bane of my existence?

I Love You, Sun

I recently upgraded my AMD 2800+ to a Intel Core 2 Duo 3.06GHz and 7200k RPM HDD. My attempts to run Virtualbox 2 on the AMD system proved futile: the computer just wasn’t fast enough. I ended up maintaining a dual-boot system–most recently Windows 7 and Ubuntu 9.04.

I also installed OpenSUSE 11.1 to do some unit tests in Konqueror and then installed Qimo linux to see if it would be good for my 2 and 5 year old. (Linux for Kids)

I specifically got a Core 2 with the new Virtualization support which somehow magically speeds up virtual environments such as VirtualBox. VirtualBox 3 can now take advantage of it. VirtualBox kicks butt.