I am using CoffeeScript classes in conjunction with a jQuery and am loading another HTML page via ajax that, in turn, references another javascript but am having trouble getting the ajax loaded page to see the classes loaded in scripts by the parent page:
The parent page loads a javascript file (compiled from CoffeeScript):
<script src="/assets/global.js?body=1" type="text/javascript"></script>
In the CoffeeScript file there is a class:
class App
constructor: ->
...
I am loading another web page using:
$.ajax({
url: '/import/show',
success: (data) =>
$('#content').html(data)
})
This page, in turn references another Coffee/JavaScript file:
<script src="/assets/import.show.js?body=1" type="text/javascript"></script>
When this loaded javascript file contains:
alert('test')
The alert is raised, as expected. This demonstrates that the loading code is working correctly. However, if the child script contains:
app = new App()
I get an error:
Uncaught ReferenceError: App is not defined
This also happens if I put the code within a document ready function:
$(=> a = new App())
Does anyone have any idea how I can make the classes in scripts loaded by the parent page available in script loaded by child pages which are loaded via ajax?