Javascript prototype problem

I'm floundering with TypeScript and javascript.
Basically, I'm putting all my UI state onto a single object defined in Typesript.
Typescript:
module AllAppState {
    export class Appsd {
        public OrdersViewBy() {
            return GetViewFromCookie('OrderTypeViewOptions', $("#cboOrderTypes").val());
        }
        public MonthsBack() {
            //debugger;
            return GetViewFromCookie('GoBackMonths', 1);
        }
        public CustomerID() { return $("#txtCustomerID").val(); }

    }
}

Open in new window


for those not seen typescript, this compiles to:
var AllAppState;
(function (AllAppState) {
    var Appsd = (function () {
        function Appsd() {
        }
        Appsd.prototype.OrdersViewBy = function () {
            return GetViewFromCookie('OrderTypeViewOptions', $("#cboOrderTypes").val());
        };
        Appsd.prototype.MonthsBack = function () {
            //debugger;
            return GetViewFromCookie('GoBackMonths', 1);
        };
        Appsd.prototype.CustomerID = function () {
            return $("#txtCustomerID").val();
        };
        return Appsd;
    })();
    AllAppState.Appsd = Appsd;
})(AllAppState || (AllAppState = {}));
//# sourceMappingURL=AppState.js.map

Open in new window

Then in the calling code I'm tyring to dynamically call these procedures but I can't seem to get to them...basic javascript I know, but...
for (pieceAppState in propertyValue()) {
    dataToSend[propertyName] = pieceAppState();//Can't call functions here!!!!
}

Open in new window

Silas2Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
for (var obj in someCollection) {
  if (typeof someCollection[obj] === "function") someCollection[obj]();
}
0
 
Silas2Author Commented:
What I don't understand is that all the pieceAppState in propertyValue() (which returns the object Appsd) are strings, not functions, but they are defined as functions in the object e.g. Appsd.prototype.CustomerID = function (), how do I get to the CustomerID() function (without hard-coding which does work)
0
 
Michel PlungjanIT ExpertCommented:
Perhaps you mean

var ID = propertyValue[pieceAppState].CustomerID();
0
 
Silas2Author Commented:
The problem with that is that I have to hard-code the 'CustomerID();' bit, I wanted a way to iterate the prototype.myFuncs= function() and call each one in turn without hardcoding the names.
0
 
Silas2Author Commented:
By jove you're right!
0
All Courses

From novice to tech pro — start learning today.