Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firefox无法生成使用TypeScript生成的类的实例_Javascript_Firefox_Typescript - Fatal编程技术网

Javascript Firefox无法生成使用TypeScript生成的类的实例

Javascript Firefox无法生成使用TypeScript生成的类的实例,javascript,firefox,typescript,Javascript,Firefox,Typescript,我有一个简单的类来包装一个网格控件,我把它放在一个名为Components的模块中,当我在Firefox 14.0.1中测试它时,我得到: TypeError:组件。网格不是构造函数@http://... 下面是TypeScript生成的代码: var Components; (function (Components) { Components.gridDefaults = { datatype: "json", autowidth: true,

我有一个简单的类来包装一个网格控件,我把它放在一个名为Components的模块中,当我在Firefox 14.0.1中测试它时,我得到:

TypeError:组件。网格不是构造函数@http://...

下面是TypeScript生成的代码:

var Components;
(function (Components) {
    Components.gridDefaults = {
        datatype: "json",
        autowidth: true,
        rowNum: 30,
        rowList: [
            10, 
            20, 
            30
        ],
        viewrecords: true,
        sortorder: "asc",
        pager: "#grid-pager"
    };
    var Grid = (function () {
        function Grid(selector, options) {
            var opts = Components.gridDefaults;
            if(options !== undefined && options !== null) {
                $.extend(opts, options);
            }
            this.grid = $(selector).jqGrid(opts);
        }
        Grid.prototype.setToolbar = function (options) {
            var pager = this.grid.getGridParam().pager;
            if(pager !== undefined && pager !== null) {
                this.grid.navGrid(pager, options);
            }
            return this;
        };
        Grid.prototype.jqGrid = function () {
            return this.grid;
        };
        Grid.prototype.filter = function (criteria) {
            this.grid.setGridParam({
                page: 1,
                postData: criteria
            });
            this.reload();
        };
        Grid.prototype.reload = function () {
            this.grid.trigger("reloadGrid");
        };
        return Grid;
    })();
    Components.Grid = Grid;    
})(Components || (Components = {}));

//@ sourceMappingURL=grid-component.js.map
这里是Firefox抱怨缺少构造函数的一行:

var grid = new Components.Grid("#grid-container", {
            url: "/Home/Data",
            colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
            colModel: [
                { name: 'id', index: 'id', width: 55 },
                { name: 'invdate', index: 'invdate', width: 90, jsonmap: "invdate" },
                { name: 'name', index: 'name asc, invdate', width: 100 },
                { name: 'amount', index: 'amount', width: 80, align: "right" },
                { name: 'tax', index: 'tax', width: 80, align: "right" },
                { name: 'total', index: 'total', width: 80, align: "right" },
                { name: 'note', index: 'note', width: 150, sortable: false }
            ],
            jsonReader: {
                id: "id",
                repeatitems: false
            }
        });

我想听听@TypeScript团队的消息。

我不是TypeScript团队的成员,也从未使用过它。但我相信这不是打字稿的问题。问题是您试图覆盖Firefox作为本机包含的内容,即
组件

如果你改成

var Comps;
(function (Components) {  // keep the local name or change to Comps, as you like
    Components.gridDefaults = {
    // ... 
})(Comps || (Comps = {}));
var grid = new Comps.Grid("#grid-container", { /* ... */ });
我认为这样会更好


我假设这意味着更改您的Typescript模块名称。但我对此一无所知。

+1-组件对于Firefox来说确实是一个保留词:Scott,谢谢你让我摆脱了另一个愚蠢的时刻。。。你搞定了!!