I am reading Javascript the Good Parts and came across the following snippet under Chapter 5 Inheritance:
var coolcat = function (spec) {
var that = cat(spec),
super_get_name = that.superior('get_name');
that.get_name = function (n) {
return 'like ' + super_get_name() + ' baby'; return that;
}
}
I am confused by the coma after cat(spec) in line 2. What does the line do exactly? (line 2 +line 3)
Thanks
That’s just a shortcut for declaring two variables in one statement, it is equivalent to this:
The comma is actually an operator in JavaScript:
A
varstatement is made up of one or more expressions of the form:where the square brackets indicate an optional component. The general
varstatement looks like this:You’ll usually only see the comma operator used in
varstatements andforloops:but it can be used in other places.