镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Proposal. Internal class declaration. #4460

Description

@xLama

I think it´s a good idea to let an internal class declaration:

class A{
   class B{}
}

Emit proposal:

var A = (function () {

     var B = (function () {
    function B() {
    }
    return B;
})();


    function A() {
    }
    return A;
})();

We can use it to make Singleton very easy.

class Singleton{

    class B{
        private enforcer:string;
    }

    private static _instance:Singleton;

    constructor(enforcer: B){}

    public static get instance():Singleton{
        if (Singleton._instance === undefined){
            Singleton._instance = new Singleton(new B())
        }
        return Singleton._instance;
    }
}

Related: #3266

Activity

  1. kitsonk commented on Aug 26, 2015

    @kitsonk
    Contributor

    How would you propose emitting this when targeting ES6, since that isn't valid ES6?

  2. RyanCavanaugh commented on Aug 26, 2015

    @RyanCavanaugh
    Member

    This doesn't add enough value over already-supported local types:

    class A {
        static B = class {
            x;
            y;
        }
    
        getInstance() {
            return new A.B();
        }
    }
  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions