I have following code
It's null because you're calling the script before the DOM has been loaded.
null
Wrap your script in a function which will be invoked onload, e.g.:
onload
window.onload = function() { var q = new foo(); q.run('yellow'); };