Question: I have a script that knows to load dynamiclly scripts that contains javascript classes.
i'm loading the class script using the following code:

```
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "myscript.js";
head.appendChild(script);

```

i'm then trying to create the new class using eval:

```
var classObj = eval(" new MyClass()" );

```

the problem is that the code of the eval is being executed bofre the script has been loaded into memory and i get an error that the `MyClass is undefined.` 

Is there a way to synch these events? i need to make sure the script is fully being loaded into memory before i can start allocating classes from it.

Answer: 
Use the [jQuery](http://jquery.com/) (a JavaScript library) `[getScript](http://docs.jquery.com/Ajax/jQuery.getScript#urlcallback) function to load your script async. Use the callback function to create your objects. Example:`

```
$.getScript("script.js", function () {
  var classObj = new MyClass();
});

```
Are you sure that adding a `<script>` element to the DOM will cause the browser to actually evaluate the script at all? I have a vague memory of reading somewhere that it doesn't, but perhaps I inhaled a bit too much oven cleaner yesterday.