I'm attempting to build an add-on for Firefox using the JPM utility. If I place the following in index.js, 'bar' is echoed out into the Browser Console without any issues
'use strict';
function Foo() {
this.$data = false;
}
Foo.prototype.change = function(data) {
this.$data = data;
};
var Test = new Foo();
Test.change('bar');
console.log(Test.$data);
But if I place the following in a file called test.js
'use strict';
function Foo() {
this.$data = false;
}
Foo.prototype.change = function(data) {
this.$data = data;
};
module.exports = new Foo;
and require it from index.js
var Foo = require('js/test');
Foo.change('bar');
I get a TypeError complaining that $data is read-only. How can I require third-party modules that use constructor function properties?
I guess this happens due to security reasons.
Anyway, export the Foo constructor and create the Foo object at the scope of index.js