JPM

2015-04-02 24 views
0

中的第三方模塊構造函數屬性變爲只讀使用JPM實用程序嘗試構建Firefox的加載項。如果我把在index.js以下,「棒」是呼應出到瀏覽器控制檯沒有任何問題JPM

'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); 

但是,如果我把一個文件中的以下稱爲test.js

'use strict'; 

function Foo() { 
    this.$data = false; 
} 

Foo.prototype.change = function(data) { 
    this.$data = data; 
}; 

module.exports = new Foo; 

並要求從index.js

var Foo = require('js/test'); 
Foo.change('bar'); 

我得到一個TypeError抱怨$數據是隻讀的。我如何需要使用構造函數屬性的第三方模塊?

回答

0

我想這是由於安全原因。

反正導出富構造和index.js的範圍創建Foo對象

+0

這將在這個簡單的例子,但在我的實際使用情況我使用這種模式從多個文件需要的模塊的工作,然後被index.js需要 – ionclash 2015-04-03 16:57:11

相關問題