1

I was going through a library of a javascript plugin which was using this syntax. what does the following statement means syntactically in JavaScript

simpleCart = function (options) {
    },$engine,cartColumnViews;

later the code uses simpleCart in many places. What does simpleCart refer to at the end of the statement.

EDIT1 : http://simplecartjs.org/assets/js/simpleCart-latest.php search for "main simpleCart object"

David
  • 4,634
  • 7
  • 35
  • 42

3 Answers3

5

My psychic powers tell me there's a var just before that (or just before a list of other values before that).

var a,b=2,c;

will define a, b and c, and set b to 2. So the code you found is setting simpleCart to a function, and defining $engine and cartColumnViews for future use (see the comments for really deep JavaScript details which are beyond the scope of this question!).

Dave
  • 44,275
  • 12
  • 65
  • 105
  • Assuming there is a `var` at the start, the OP code creates all the variables first, then assigns a function to `simpleCart` since declarations are processed before any code is executed. ;-) – RobG Mar 06 '13 at 02:08
  • well what do you know, seems it is. I had to make a jsfiddle to convince myself: http://jsfiddle.net/sfZPX/1/ – Dave Mar 06 '13 at 02:11
  • well the answer is still valid anyway! – Dave Mar 06 '13 at 02:12
0

That's very strange code, but the function and the $engine don't do anything so the result is essentially the same as simpleCart = cartColumnViews.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

I'm assuming it is variable declaration. simpleCart is variable that function assigned to it.

Better reference here: var functionName = function() {} vs function functionName() {}

Community
  • 1
  • 1
ins429
  • 23
  • 2