Closed Bug 869983 Opened 11 years ago Closed 11 years ago

Class does not seem to work as advertised in the documentation (for FX 20, 21)

Categories

(Add-on SDK Graveyard :: Documentation, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: mgoodwin, Assigned: zer0)

Details

Component: General → Documentation
So, the issue here is that in Add-on SDK 1.14, `Class` returns a non extensible constructor, with a non extensible `prototype`. It means that this is working:

    var { Class } = require('sdk/core/heritage');
    var Dog = Class({
      initialize: function initialize(name) {
        this.name = name;
      },
      type: 'dog',
      bark: function bark() {
        return 'Ruff! Ruff!'
      }
    });

But this is not:

    var { Class } = require('sdk/core/heritage');
    var Dog = Class({
      initialize: function initialize(name) {
        this.name = name;
      }
    });

    Dog.prototype.type = 'dog';
    Dog.prototype.bark = function bark() {
        return 'Ruff! Ruff!'
    };

And if the add-on dev is not using "use strict", no exceptions are raised, it will silently fails – properties not added to the prototype.

Probably the misleading part in the documentation was:

> Please note that Class is just an utility function which we use in SDK, and
> recommend our users to use it, but it's in no way enforced. As a matter of fact
> since result is just a plain constructor function with proper prototype chain
> setup

However notice that after 1.14, `Class` returns an extensible constructor and prototype, so also extends the prototype works without issues.

Will, I don't think we need to updated the 1.14 documentation, but what do you think?
Flags: needinfo?(wbamberg)
I don't think it's worth revving the 1.14 documentation for this.
Flags: needinfo?(wbamberg)
In that case I will set it as "WONTFIX", because the issue is related only for 1.14 documentation.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.