These are chat archives for systemjs/systemjs

5th
Feb 2015
Joe Pea
@trusktr
Feb 05 2015 03:53
This message was deleted
Joe Pea
@trusktr
Feb 05 2015 03:59
This message was deleted
Joe Pea
@trusktr
Feb 05 2015 04:57
@guybedford I'd like to export a class (constructor) from a module (not a factory function that wraps an actual constructor) but I'd like for instances made with that exported constructor to each have a private closure. Make sense? Is that possible? f.e. I don't think I can do export default foo() in a module where foo gets called each time the module is imported so that the imported value is dynamic, can I?
Where Foo.js would be something like
function foo() {
  var privateVariable = "foo"
  return class Foo {
    constructor() {
      // do something with privateVariable
    }
  }
}
export default foo()
Joe Pea
@trusktr
Feb 05 2015 05:03
So I'd be returning the class directly, which is advantageous because then it's prototype can be directly manipulated outside of the module, but if I just export foo then I can't modify the prototype of the Foo class directly outside of the module, I'd be modifying the foo function. Is there a way?
Joe Pea
@trusktr
Feb 05 2015 05:11

I suppose I could export foo then outside the module do

var instance = new (foo())()

so that each instance has it's own closure, but the problem is that extending the class means that each Foo prototype will share the closure, f.e.

var Foo = foo()
class Bar extends Foo {
  // ...
}

So now each time I make a new Bar() then it's prototype will be Foo, but each instance of the Foo prototype will share the private closure, which isn't what I want. hmm...

Joe Pea
@trusktr
Feb 05 2015 05:16
Way off topic, sorry. My original question was about if export foo() is possible.
Guy Bedford
@guybedford
Feb 05 2015 11:27
@trusktr not really my area, but no it's not possible - ideally this would just be Symbols I think? The easy method is just to use instance variables like this.privateVar_