tags:

views:

46

answers:

2

I have a function acting as a constructor that, when called, gets as far as the function definition in the debugger, but never to the function body. Is there a common reason this may happen that I am overlooking? Example code below:

myconstructor.js

function MyConstructor(optionalParam) { //this breakpoint gets hit
    var newobj = {}; //breakpoint never hit
    //code to check for null parameter
    //other code
};

main.js

var myConstructor = new MyConstructor();

There must be something I have overlooked, but I can't see what that is. Neither firefox/firebug nor VS report errors or warnings.

Thanks!

A: 

Would the function not have to be inside a class for you to be able to instantiate it?

Chief17
Javascript doesn't have classes
Jonas H
Nope, it is declared globally (or more accurately it is declared within 'window'.) So the call could just as easily be var myConstructor = new window.MyConstructor(). Just as a sanity check, I do have other 'classes' defined in this same fashion (that work.)
Mike S
Hmm I guess you're right, but I found this: http://www.webmonkey.com/2010/02/make_oop_classes_in_javascript/Which is kinda what I meant (although it may not be the cause of the problem)
Chief17
have you tried just putting an alert('test'); in there instead? just to check everything up to that point is working?
Chief17
A: 

Your syntax looks correct, and it works inline. Did you make sure you closed all your script tags?

<script src="myconstructor.js" type="text/javascript">

<script type="text/javascript">
  var myConstructor = new MyConstructor();
</script>

Won't work. If that's not it, I got absolutely nothin'.

Hooray Im Helping
The tags were closed, but out of order (stupid mistake.) Marked as answer since it was a script tag related problem. Thanks.
Mike S