I’ve been watching some documentation, and I’m still confused.
I want to do a callback function on this:
$('.scroll-pane').jScrollPane();
Now the documentation shows this example
function fn1( value ){
console.log( value );
}
How come the semicolon is at the end in my first example, and in the second the semicolon only seems to be at the end of another callback function as far as I can tell?
Thanks everyone 🙂
The semicolon in JavaScript is used to terminate a statement. Your first example is a statement (it calls the
jScrollPanefunction on the object returned by the$('.scroll-pane')function call). Your second example is a function declaration, which is not terminated with a semicolon (nor areforloops,ifblocks, etc.). Neither of your examples seems to have anything to do with callbacks, just calls.Re your comment:
Not sure what you mean by “finishes.” Calling
jScrollPaneon an element just creates the pane (immediately). If you want to have thejScrollPanecall you back when an event occurs, you bind to the event. For instance:That hooks up an anonymous function to be called when the event occurs. Or you can use a named function:
(The function declaration doesn’t have to be right there where the
bindcall is, in this case.)More in the docs.