html5 - How to include a JavaScript object in a separate file -


i'm trying include separate .js file can pull in class created doesn't work, can tell me why?

playercharacter.js

function playercharacter() { this.x = 0;  this.y = 0;  this.dx = 5; this.dy = 5; }   playercharacter.prototype.sayhello = function() {  alert ('hello'); }; 

index.html

<html> <head> <script src="js/playercharacter.js" type="text/javascript" ></script> </head> <body>  <script type="text/javascript" > var player = new playercharacter(); player.sayhello(); </script> </body> </html> 

you forgot wrap js-code <script> tags

<html>  <head>   <script src="js/playercharacter.js" type="text/javascript" ></script>  </head>  <body>   <script type="text/javascript" >    var player = new playercharacter();    player.sayhello();   </script>  </body> </html> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -