i am dustin diaz

a JavaScriptr...

boosh.

don't worry about it.

Code choices: What's better?

Ala Snook prompt, which of the following sets of JavaScript do you prefer or think is better, and why?

Passing Objects

Method A

var o = {

  foo : 'bar',

  baz : true,

  bla : 1

};

fn(o);

Method B

fn({

  foo : 'bar',

  baz : true,

  bla : 1

});

Min-height

Method A



/* ala http://www.dustindiaz.com/min-height-fast-hack */

selector {

  min-height:500px;

  height:auto !important;

  height:500px;

}

Method B



selector {

  min-height:500px;

}

* html selector {

  height:500px;

}

DOM 'load' state

Method A

...

<style>

...

.dn {

  display:none;

}

...

</style>

<body>

...

<div class="dn">

Method B

<div style="display:none;">

Function Declaration

Method A

function fn() {

  // do stuff here

}

Method B

var fn = function() {

  // do stuff here
};

this is who i am

Hi, my name is Dustin Diaz and I'm an Engineer @ObviousCorp. Previously @Twitter, @Google, and @Yahoo, author of Strobist® Info co-author of JavaScript Design Patterns, co-creator of the Ender JavaScript Framework, a Photographer, and an amateur Mixologist. This is my website. Welcome!

On this site I write about JavaScript. You can also follow along with my open-source work on Github.

This site is optimized and works best in Microsoft Internet Explorer 6.