Skip to content

Suggestion: Anonymous/Unnamed Modules #206

Closed
@omidkrad

Description

@omidkrad

Suggestion moved over from codeplex.

I would like to suggest the following: Why not have anonymous/unnamed modules? The following code snippet totally makes sense for me to compile:

module {
  class Simple {

    constructor(public name: string) {}

    greet(who: string) {
      return "Greetings "+ who +", I'm "+ this.name +"!";
    }

    static main() {
      var s = new Simple('Flynn');
      console.log(s.greet("Program"));  
    }

  }

  Simple.main()
}

The generated code should be wrapped in a closure function and not cluttering the global scope.

(function () {

 // ...

})();

Also it would be nice to have a compiler option to put everything compiled in an anonymous module so that the global namespace is not cluttered.

The above snippet is with little modification from: https://gist.github.com/3916195

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions