I’m just getting started with Javascript, jQuery, and jQuery Mobile. I’m trying to go through a tutorial online, but I’m getting caught up on the mobileinit event handler. Here is the code:
<script type="text/javascript">
$(document).bind("mobileinit", function() {
Notes.testHelper.createDumyNotes();
Notes.controller.init();
});
</script>
If I put an alert before and right after Notes.testHelper.createDummyNotes(); the alert is called. However, if I put the alert right after Notes.controller.init(), the alert isn’t called. I imagine this means the code stopped in that function. However, if I put an alert right before the closing script tag outside of the function, that alert is called–This is what confuses me. How can a method hang and not allow the rest of a function to complete but still let the script complete?
As an interesting aside, I forgot to put the script tags around this .bind function at first, and the html was styled correctly. However, once I put the tags around this function, the html appeared but wasn’t styled.
Any suggestions? As I said, I’m new to javascript, so this could be a fundamental misunderstanding of the way the language executes.
Thanks for your help!
The contents of
$(document).bind("mobileinit", function() { ... }will be called when themobileinitevent is triggered, which will be AFTER the code between thescripttags are read. This is why thealertyou placed just before the closingscripttag is executed.If you put
alert(1);before the closing tag, andalert(2);after thefunction() {andalert(3)after thecreateDumyNotes(), you will probably get1and2but not3.I think you’re on the right path in that the error is occurring in the
createDumyNotes()function. I suggest you get into that function with sometry { ... } catch(e) { ... }and pinpoint where the error is occurring (assumingNotesandNotes.testHelperare valid objects, andNotes.testHelper.createDumyNotes()is an existing function.EDIT
I just noticed that your function is
createDumyNotes()instead ofcreateDummyNotes(). Is this nothing more than a misspelling?