inheriting statics

Brendan Eich brendan at mozilla.org
Sun Jan 7 11:32:13 PST 2007


On Jan 7, 2007, at 9:50 AM, Peter Hall wrote:

> "Since inheritance does not apply to static members"
>
> Your assumption is what I was questioning. Why doesn't inheritance
> apply to static members?

Right, the assumption should be justified.  One rationale is by  
extension of ES1-3 (plain ol' JS):

function SpecialString(s) { this.value = s; }
SpecialString.prototype = new String;
SpecialString.prototype.toString = function () { return this.value; }
s = new SpecialString("hello");
t = s.charCodeAt(3);
alert(t);
alert(SpecialString.fromCharCode(t));

The last line throws TypeError: SpecialString.fromCharCode is not a  
function.

Inclusion of statics in the scope chain within instance methods is a  
convenience afforded by the new special form of methods defined via  
function definitions nested in a class definition. But it's not  
inheritance.

/be




More information about the Es4-discuss mailing list