6 ms·
Because all the import * as Foo from "foo" produce the same singleton with shared state. What I would like is something like function(param1, param2){
by afiori 4y ago
Because all the import * as Foo from "foo" produce the same singleton with shared state. What I would like is something like
function(param1, param2){
return module Name {
import {param1} from super;
export let A = param1 + 1;
// This line would cause an error as
// param2 is not imported from the enclosing scope
// export let AA = param2 + 2;
}
}
- hajile 4y agoSingleton is orthogonal to namespaces. One is about data creation and the other about naming stuff. If I want to create new pieces of data, I have to make an allocation with a constructor. Reusing methods provided by modules is effectively the same as classes (the two being mathematically equivalent, but closures not having all the footguns). This is true no matter if your code is OOP, imperative, or functional.