Possible Duplicate:
JavaScript: var functionName = function() {} vs function functionName() {}
How are Foo and Bar any different ?
If objects were only functions, why was this new syntax introduced ? (Foo).
var Foo = function(arg) {
this.attr = arg;
};
function Bar (arg) {
this.attr = arg;
}
/*
>>> f = new Foo(3)
Object { attr=3}
>>> f.attr
3
>>> b = new Bar(40)
Bar { attr=40}
>>> b.attr
40
*/
A fair amount of documentation I'v read proposes the first syntaxe, but the second one seems to work just as well.