views:

100

answers:

3

I'm using this simple code: http://ejohn.org/blog/simple-javascript-inheritance/
Using this "library", I made this simple class:

var Person = Class.extend({
  init: function(openningSentence) {
    this.say(openningSentence);
  },

  say: function(words) {
    alert(words);
  }
});

The problem with this class, is that I can't call a function using the variable "this" (line 3 in the code gives an error: unknown method "say").

Does anybody knoes if there's a solution for this problem?
Btw - I'm using jquery, so if there's a jquery-based solution It'll be great :)

A: 

How are you calling the function?

var p = new Person();

Does that give you the error?

Pointy
@Pointy: not to be a buzz killington here, but shouldn't this be a comment?
Andy E
Well he left a lot out of the question, so it was intended as a *potential* answer.
Pointy
@Andy, not necessarily. The answer to that followup question looks like it will probably be the correct answer.
eyelidlessness
Well, uh, carry on then :-)
Andy E
A: 

Ohh, That suddenly worked. But in my real class (not test) it doesn't works :P

Zippo
I'll try to fix my real class. Thanks for those who tried to help!
Zippo
+2  A: 

Here is a short, self contained example - http://jsfiddle.net/JgMFE/. You can see that it works fine using the code you provided along with:

(new Person("Hello"));

​ It alerts "Hello", just as intended.

Andy E
Yes it works, thank you. I was probably drunk when I wrote this question :(
Zippo