Page MenuHomePhabricator

Documentation for inheritClass has broken example
Closed, ResolvedPublic

Description

The docblock for inheritClass uses this code snippet as an example:

function Thing() {}
Thing.prototype.exists = function () {};

function Person() {
    this.constructor.super.apply( this, arguments );
}
oo.inheritClass( Person, Thing );
Person.static.defaultEyeCount = 2;
Person.prototype.walk = function () {};

function Jumper() {
     this.constructor.super.apply( this, arguments );
}
OO.inheritClass( Jumper, Person );
Jumper.prototype.jump = function () {};

Jumper.static.defaultEyeCount === 2;
var x = new Jumper();

When actually executed, this will result in an infinite recursion since this.constructor.super does not change as the call progresses up the inheritance chain.


Version: unspecified
Severity: trivial

Details

Reference
bz62405

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:52 AM
bzimport added a project: OOjs core.
bzimport set Reference to bz62405.

Ah, of course. Though "super" allows avoiding harcoding of the parent's class name, it does require you to reference the "current" class name as it otherwise will indeed never resolve.

Proper syntax is:

function Person() {

Person.super.apply( this, arguments );

}

Change 117479 had a related patch set uploaded by Krinkle:
inheritClass: Use Class.super instead of this.constructor.super

https://gerrit.wikimedia.org/r/117479

Change 117479 merged by jenkins-bot:
inheritClass: Use Class.super instead of this.constructor.super

https://gerrit.wikimedia.org/r/117479