# Javascript class+call base class?

I'm sure this can be done in less lines and in a more clean way?

function BaseClass() {
BaseClass.prototype.talk = function () {
}
}

function MyClass() {
BaseClass.call(this);
}
MyClass.prototype = new BaseClass();
MyClass.base = {};
MyClass.base.talk = MyClass.prototype.talk;
MyClass.prototype.talk = function () {
MyClass.base.talk();
}

var a = new MyClass();
a.talk();

-
Why are you declaring BaseClass.prototype.talk inside the constructor? –  Joseph Silber Jan 13 '13 at 6:51
@JosephSilber: I don't know. Am I not suppose to do it there? Why wouldn't I declare it there? –  acidzombie24 Jan 13 '13 at 6:52
Because then you're recreating the function every time you create a new object. The prototype is used to store functions that are shared between your objects. –  Joseph Silber Jan 13 '13 at 6:54
@JosephSilber: Ah, so how would you rewrite all of this code? –  acidzombie24 Jan 13 '13 at 7:00
You basically have it all figured out. I changed it around a tiny bit, and posted it below. –  Joseph Silber Jan 13 '13 at 7:17

function BaseClass () {}

BaseClass.prototype.talk = function () {
}

function MyClass() {
BaseClass.call(this);
}

MyClass.prototype = new BaseClass();
MyClass.base = BaseClass.prototype;

MyClass.prototype.talk = function () {

cool but the talk.apply(this, arguments); looks nasty –  acidzombie24 Jan 13 '13 at 7:32