Javascript: Changed to console.log and closures

Update to support nodejs and closures style.