Extending classes the proper way

is there a proper way to extend a class?
the current method i’m using is this:

function base() { …
function child() { …
child.prototype = new base();
child.prototype.constructor = child;

now this is not real inheritance. for 1 reason, a base() is created even when no child() are created. and even if i create 10 child(), there is only 1 base() created (the proper inheritance will create 10 bases if i create 10 childs, 1 for each child)

is there a way to achieve real inheritance in javascript? (the main problem now is that i cannot allow base() to run until there is an explicit call to child())

JavaScript doesn’t have classes so you can’t extend them because they don’t exist.

JavaScript does have objects and the way that you go about creating new objects based on existing objects works best if you forget all about how you would extend classes.

In JavaScript either an object has been created (and its constructor has been run) or it hasn’t.

Probably the simplest way to achieve what you are after would be to create the base from within the child constructor but only if the base doesn’t already esist.

heys cool, thanks for the reply