libseed-list module import suggestion
- From: Jonatan Liljedahl <lijon kymatica com>
- To: Seed - Gnome Javascript <libseed-list gnome org>
- Subject: libseed-list module import suggestion
- Date: Mon, 14 Jun 2010 16:18:11 +0200
Currently, importing another JS file imports all toplevel variables. 
This is not very nice, since you can't have private stuff without 
resorting to some hack like this:
var _exports = (function() {
    var x = 123;
    var y = 42;
    var f = function() { print(x) };
    return {
        y:y,
        f:f
    }
})();
for(var k in _exports) {
    this[k] = _exports[k];
}
I suggest that if a variable EXPORTS is found, only the symbols listed 
in it will be exported:
  EXPORTS=[foo,bar,x,y];
seed_importer_handle_file() would then do something like this:
  if global.EXPORTS exist and isArray:
     exports = newEmptyObject()
     for each s in EXPORTS:
        exports[s] = global[s]
  else:
     exports = global
  return exports
One could additionally have a naming convention where symbols prefixed 
with underscore is ignored unless EXPORTS is defined.
What do you think?
/Jonatan
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]