Solved

Javascript prototype problem

Posted on 2014-03-24
5
186 Views
Last Modified: 2014-03-25
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

0
Comment
Question by:Silas2
  • 3
  • 2
5 Comments
 

Author Comment

by:Silas2
ID: 39950631
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39952841
Perhaps you mean

var ID = propertyValue[pieceAppState].CustomerID();
0
 

Author Comment

by:Silas2
ID: 39952963
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 300 total points
ID: 39953040
for (var obj in someCollection) {
  if (typeof someCollection[obj] === "function") someCollection[obj]();
}
0
 

Author Comment

by:Silas2
ID: 39953071
By jove you're right!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now