Why do I get "undefined is not a function. The problem occurs when I want to create the Player variable in the main function. Everything worked before I used the onload function and the init WebGL and function main, didn't exist. Their content was just written in a script in the html file. So there is no problem with the creation of the new Player in the external file. Somehow the function just does not exist.
Here is a part of my html file
<head>
<script src="player.js" type="text/javascript"> </script>
<script src="main.js" type="text/javascript"></script>
</head>
<body onload="initWebGL()">
<canvas id="canvas" width="800" height="600"> </canvas>
</body>
my main.js
function initWebGL() {
//......
main();
}
function main() {
// Player
var Player = new Player();
//.....
1 Answer 1
It's giving you this error because you named your variable with an upercase, wich is the exact same name as your object Player, try changing your line:
var Player = new Player();
to
var player = new Player();
Look at this fiddle to see it in action, the wrong button log your error in the console while the right button works !
Edit: in your comments, you talked about the same error with var Camera = new Camera(); Just change it to var camera = new Camera(); and your problem should be gone, don't forget to change your code accordingly.
undefined is not a functionis from? (which line?)