angularjs - TypeScript: Can't define class inside an IIFE -
i want define class inside iife using typescript , keeps getting error, class can defined either in module or file
. below code not work.
(function(){ // error here class person { } })()
the reason need because don't want expose global variables, not module. may wonder why, because add them angular modules in below way
(function(){ angular.module('app').controller('homecontroller', homecontroller); // error here class homecontroller { } })();
when create class, generates iife you:
the class:
class example { }
results in javascript:
var example = (function () { function example() { } return example; })();
if want keep classes out of global scope, can use modules:
module stack { export class example { } export class overflow { } }
only stack
module appears in global scope.
var stack; (function (stack) { var example = (function () { function example() { } return example; })(); stack.example = example; var overflow = (function () { function overflow() { } return overflow; })(); stack.overflow = overflow; })(stack || (stack = {}));
if want go step further, can use external modules - when that, none of classes or modules added global scope.
Comments
Post a Comment