0

I recently asked a question but couldn't really understand the answer. Here's what I have been able to understand. Can someone please verify if this is the correct way to go about doing something similar to C# where I have namespaces? Note that below are three files and they all have references to each other but these are not show here:

/Admin/dialog/start.ts
module Admin.dialog {
    export function x() { };
    Admin.grid.y(); // executes the function inside of file2.ts
}

/Admin/dialog/file1.ts
module Admin.dialog {
    export function y() { };
}

/Admin/grid/file2.ts   
module Admin.grid {
    export function y() { };
}

1 Answer 1

2

Here is my suggested structure:

./Admin/Dialog.ts

module Admin {
    export class Dialog {
        x() {
            this.y();
        }

        y() {

        }
    }
}

./Admin/Grid.ts

module Admin {
    export class Grid {
        y() {
        }
    }
}

You can then use these modules like this:

///<reference path="./Admin/Dialog.ts" />
///<reference path="./Admin/Grid.ts" />

var dialog = new Admin.Dialog();
dialog.x();

var grid = new Admin.Grid();
grid.y();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your advice. The only one thing I am not sure of is I have many functions in the directory /Admin/Dialog/ directory and each of these functions are in their own file. For example x.ts and y.ts and z.ts for the functions x(), y() and z(). Given this scenario how would you suggest I use modules?
I would move all of those functions into the "Dialog" class in the "Admin" module as they are related and are likely to change for the same reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.