Take a look at the anonymous jQuery function from the jfiddle snippet below. There are other libraries as external references to this jfiddle, so I'm just guessing this is jQuery syntax.
Code snippet:
$(function() {
var canvas = new draw2d.Canvas("gfx_holder");
var x = 20,
y = 20;
addArrowToConnection();
injectSetPosition();
var previousRec, newRec;
for (var i = 1; i <= 64; i++) {
newRec = addRec(canvas, i, x, y);
if (i / 8 == Math.floor(i / 8)) {
y = y + 80;
x = 20;
} else {
x = x + 80;
}
if (previousRec != null && newRec != null) {
var conn = new draw2d.Connection();
conn.sourcePort = previousRec.port;
conn.targetPort = newRec.port;
var label = new draw2d.shape.basic.Label({
text: "Label"
});
label.setColor("#0d0d0d");
label.setFontColor("#0d0d0d");
label.setStroke(0);
var arrow = new draw2d.decoration.connection.ArrowDecorator(10, 6);
conn.setTargetDecorator(arrow);
conn.setRouter(new draw2d.layout.connection.DirectRouter());
conn.add(label, new draw2d.layout.locator.ParallelMidpointLocator());
canvas.add(conn);
}
previousRec = newRec;
}
});
All of the other functions within this jfiddle are using one of the JavaScript standard function notations (var functionName = function() {} vs function functionName() {}) except the one above. If you try replacing the syntax with the other three notations, the code doesn't work. What is significant about this notation? Why does only the last syntax work?
var fun = function() { ... } // doesn't work
function fun() { ... } // doesn't work
(function() { ... })(); // doesn't work
$(function() { .. }); // works!!!!!!!!!!!!!!!