Permalink
Browse files

Bug 674191 - Document that module exports are frozen and immutable; r…

…=gozala
  • Loading branch information...
1 parent 67b2d9b commit 4fb5bdd5e5c8b4f86bf6cc3b9dd378023224ec3b @wbamberg wbamberg committed Jul 28, 2011
Showing with 13 additions and 0 deletions.
  1. +13 −0 static-files/md/dev-guide/addon-development/commonjs.md
@@ -21,6 +21,19 @@ SDK modules it uses.
![CommonJS modules](media/commonjs-modules.jpg)
+The SDK
+[freezes](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/freeze)
+the `exports` object returned by `require`. So a if you import a module using
+`require`, you can't change the properties of the object returned:
+
+ self = require("self");
+ // Attempting to define a new property
+ // will fail, or throw an exception in strict mode
+ self.foo = 1;
+ // Attempting to modify an existing property
+ // will fail, or throw an exception in strict mode
+ self.data = "foo";
+
## CommonJS Packages ##
A CommonJS **package** is a structure which can wrap a collection of related

0 comments on commit 4fb5bdd

Please sign in to comment.