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
Post a Comment