0

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');
2
  • 2
    Have you imported Prototype.js? Commented Apr 27, 2015 at 13:54
  • 2
    @GouthamNagappa You are not learning pure JavaScript, you are learning how to use the Prototype.js library. Commented Apr 27, 2015 at 13:58

2 Answers 2

2

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

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

Comments

1

Did you added the script inclusion?

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.