Trying to load a HTML page including JavaScript containing the first 2 (implicitly "correct" "intended") paragraphs Google Chrome Browser ("Version 55.0.2883.87 (64-bit)" on Kubuntu 16) already shows errors (try F-12 key and click on console to see).
Since you did not explictly described how the JS-code is intended to be used, this is at least a version without triggering error messages, hope it meets what you are looking for (if not, please specify in detail):
If you create a file test1.js containing:
class Person {
constructor(name) {
this.name = name;
}
}
Person.prototype.name ="no name";
Person.prototype.type ="human";
Person.prototype.greet = function() {
console.log("hi im a human");
};
Person.prototype.sayName = function(){
return this.name;
}
var john = new Person("john");
john.walk = function() {
console.log(this.name+" is walking");
}
Then loading a HTML file containing
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="test1.js"></script>
</head>
<body>
<script type="text/javascript">
john.greet();
console.log(john.sayName());
john.walk();
</script>
</body>
</html>
will output on console:
hi im a human
john
john is walking