someFunction(abc)
returns a function. The (d)
immediately calls the returned function, and passes the parameter d
to it.
Conceptually, someFunction(abc)
could be defined as something like below. Here, someFunction(abc)
returns a function which accepts a parameter (d
). It alerts the sum of abc + d
.
function someFunction(abc) {
return function (d) {
alert(abc + d);
};
}
var adder = someFunction(10);
adder(2); // 12
adder(3); // 13
// ... or
someFunction(10)(2); // 12
someFunction(10)(3); // 13
Experiment here; http://jsfiddle.net/756g3/
In your specific case, $compile('<p>{{total}}</p>')
returns a template function. You're immediately calling that template function, passing the scope
variable to it.