Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2011/07/29

More Javascript Didacticisms: Namespaces

For the draft page in the Blogger dashboard, I'm seeing sixteen javascript libraries and five extensions running in Chrome. That's a lot. Think about that next time you type var scratch = "something" .

If you want to use scratch and so does the person who wrote the popup library, your code might not work. I learned this when I was writing test code to properly create objects for jQuery's post(). I was sharing a variable that contained the URL for the JSON I was grabbing, and when I had Before commented out, After worked perfectly, but otherwise, it all crashed.

The solution? Objects.
var my_ns = {
    foo : x' ,
    bar : 14 ,
    blee : function () {
        ...
        }
    }

$(function() {
    my_ns.blee()
    } )

2011/07/28

Thank you, Stack Overflow!

I have to thank Stack Overflow again.

I code everything from SQL to Javascript, and that means that I don't really get to become expert in everything. I do alright, but there's occasionally things I just don't get, and I don't really have a community of developers around me to ask.

My most recent problem relates to hashes in Javascript connecting to JSON. You can make arrays behave like hashes in Javascript:


var hash = new Array()

hash['foo'] = 1

alert( hash.foo )



My problem was with post, the jQuery method to do AJAX with large data sets. This didn't work.




$.post( url , hash , function() { ... } , 'json' )

Because hash is an abused array, not an object. Before I figured it out, today, thanks to SO, I make a long string that looked like { 'foo' : '1' , 'bar' : '2' } and ran eval on it. Bad bad bad bad bad. I now know that it should work like this:



var hash = {}

hash['foo'] = 1

$.post( url , hash , function() { ... } , 'json' )

Thanks again, StackOverflow!

2011/07/27

What to do with massive amounts of computrons, plus quitting in front of people


I am in the bioinformatics space. Irony is, there's no way I could've paid to attend OSCON.