I've been broadening my horizons learning javascript and I have a quick question about style. I used to use a literal notation when making my code like this.
var foo = {
bar:function(){/*something*/}
};
but I would have problems accessing certain variables within the object, it would claim a few didn't exist nomatter what. So I started using this, cause it worked.
var foo = {};
foo.bar = function(){/*something*/};
But after reading around a bit I get the impression that this style isn't preferred. Not that I liked the style, it just got things to work. Is there any best practices when using the literal notation so all my variables and such will work?
Wish I had the old code that didn't work still, but I think it was a variable pointing to another variable withing the same object literal or something like that.