How can I get a reference to the external module itself within the code that sits inside that module?

Topics: General
May 16, 2014 at 3:05 PM
I wish I knew how to get a reference to a AMD module being withing that module. Does anyone know?
May 16, 2014 at 7:09 PM
Read about the "export =" syntax.
Coordinator
May 16, 2014 at 8:49 PM
@middlewest - are you asking "how do I know the name of the external module" that you're inside of? If so, it's the same as the name of the file. This is the same name that other source files will use to import it.
May 16, 2014 at 9:38 PM
@thorn0 `export =` doesn't work with AMD modules



May 16, 2014 at 9:48 PM
Edited May 16, 2014 at 9:50 PM
I am talking about a scenario of making modules loaded by RequireJS global (attached to the window object):
// File utils.ts
// AMD modules flag is ON
export function f1() {}
// a lot of other functions
export function f999() {}
(<any>window).utils = /* must be a reference to this very module with all its functions, so that it would be available in the global scope from the HTML page, what am I supposed to use to get it? */
This workaround seems to do the trick but it's ugly:
// File utils.ts
// AMD modules flag is ON
import utils = require('utils'); // <-- requesting to import this very module itself! (bizarre)
export function f1() {}
// a lot of other functions
export function f999() {}
(<any>window).utils = utils // this seems to work
May 17, 2014 at 11:25 AM
middlewest wrote:
@thorn0 export = doesn't work with AMD modules
That's not true.