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

RESOLVED WONTFIX

Status

RESOLVED WONTFIX
6 years ago
5 years ago

People

(Reporter: mgoodwin, Assigned: zer0)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Assignee)

Updated

6 years ago
Component: General → Documentation
(Assignee)

Comment 1

6 years ago
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)
Will, ping?
I don't think it's worth revving the 1.14 documentation for this.
Flags: needinfo?(wbamberg)
(Assignee)

Comment 4

5 years ago
In that case I will set it as "WONTFIX", because the issue is related only for 1.14 documentation.
(Assignee)

Updated

5 years ago
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.