0

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();
  //.....
3
  • Could you check where undefined is not a function is from? (which line?) Commented Feb 11, 2014 at 17:52
  • Make sure you don't have any syntax errors in your scripts. Commented Feb 11, 2014 at 17:53
  • the undefined is not a function occurs when i call var Player new Player(); If I unccoment this, I just get the same error one line later where i call var Camera = new Camera() which is defined in camera.js, which is not visible in the example above. Commented Feb 11, 2014 at 17:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.