Samantha J T Star
Samantha J T Star

Reputation: 32808

How can I call a function inside a function in Typescript?

I have the following script:

/// <reference path="updateAjax.ts" />
/// <reference path="updateSetUp.ts" />
/// <reference path="../../Shared/typescript/reference.ts" />

module Admin.Grid {

    export function updateField(entity: string, $link: JQuery) {

        var link = new Link($link),
            idArr = $link.attr("id"),
            idTmp = idArr.split("_");

        link.AdminParams = Admin.Shared.getAdminParams(entity),
        link.Entity = entity;
        link.InputFieldType = $link.attr('id').split('_')[1];
        link.Row = idTmp[2],
        link.PartitionKey = $("tr[id='row_" + link.Row + "']").attr('data-pk'),
        link.RowKey = $("tr[id='row_" + link.Row + "']").attr('data-rk');
        link.InputFieldValue = $link.is(":checkbox") ? $link.is(":checked") : $link.val(),

        updateSetUp(link);
        updateAjax(link);
    }
}

And in another file:

/// <reference path="../../Shared/typescript/reference.ts" />

module Admin.Grid {

    export function updateSetUp(link: Link) {
        $("#modified_" + link.Row).html('Updating');
        $("#modifiedBy_" + link.Row).html('Updating');
        $("#input_" + link.InputFieldType + "_" + link.Row)
            .next('span').remove().end()
            .after('<span class="check-waiting"></span>');
    }

}

When the first script compiles to javascript I do not see any calls to updateSetup(link) or updateAjax(link)

I'm working in VS2012 with web essentials. I get no error messages or red underline. As far as I can see all my links are correct. Deleting the files and recreating makes no difference.

Here's the javascript that's produced:

var Admin;
(function (Admin) {
    (function (Grid) {
        function updateField(entity, $link) {
            var link = new Link($link);
            var idArr = $link.attr("id");
            var idTmp = idArr.split("_");

            link.AdminParams = Admin.Shared.getAdminParams(entity) , link.Entity = entity;
            link.InputFieldType = $link.attr('id').split('_')[1];
            link.Row = idTmp[2] , link.PartitionKey = $("tr[id='row_" + link.Row + "']").attr('data-pk') , link.RowKey = $("tr[id='row_" + link.Row + "']").attr('data-rk');
            link.InputFieldValue = $link.is(":checkbox") ? $link.is(":checked") : $link.val() , Grid.updateSetUp(link);
            Grid.updateAjax(link);
        }
        Grid.updateField = updateField;
    })(Admin.Grid || (Admin.Grid = {}));
    var Grid = Admin.Grid;

})(Admin || (Admin = {}));

Upvotes: 1

Views: 1551

Answers (1)

John Dvorak
John Dvorak

Reputation: 27287

The calls are indeed there in the compiled code. Note the liberal use of commas instead of semicolons resulted in very long lines:

link.AdminParams = Admin.Shared.getAdminParams(entity) , link.Entity = entity;
link.InputFieldType = $link.attr('id').split('_')[1];
link.Row = idTmp[2] , link.PartitionKey = $("tr[id='row_" + link.Row + "']").attr('data-pk') , link.RowKey = $("tr[id='row_" + link.Row + "']").attr('data-rk');
link.InputFieldValue = $link.is(":checkbox") ? $link.is(":checked") : $link.val() , Grid.updateSetUp(link);
Grid.updateAjax(link); //<<<here and ...                                             ^here^

Upvotes: 2

Related Questions