Goutham Nagappa
Goutham Nagappa

Reputation: 7

Java Script Class.create() says class not defined

I am new to java script and I went through the following link to learn about classes. http://prototypejs.org/learn/class-inheritance. I tried running the below code in google chrome and it says "Uncaught: Reference Error: Class not defined" and I don't know why it says so. Can anyone help me through this.

here is the code, I copy pasted it from the above link:

var Person = Class.create();
Person.prototype = {
  initialize: function(name) {
    this.name = name;
  },
  say: function(message) {
    return this.name + ': ' + message;
  }
};

var guy = new Person('Miro');
guy.say('hi');
// -> "Miro: hi"

var Pirate = Class.create();
// inherit from Person class:
Pirate.prototype = Object.extend(new Person(), {
  // redefine the speak method
  say: function(message) {
    return this.name + ': ' + message + ', yarr!';
  }
});

var john = new Pirate('Long John');
john.say('ahoy matey');

Upvotes: 0

Views: 1667

Answers (2)

Lucas Sodré
Lucas Sodré

Reputation: 77

It seems that you're not referenciating the Prototype.js You need to add the Prototype.js to your code

https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js

Adding <script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js"></script> to your code should solve the problem

Upvotes: 2

manzapanza
manzapanza

Reputation: 6225

Did you added the script inclusion?

<script type="text/javascript" src="/path/to/prototype.js"></script>

Upvotes: 1

Related Questions