Solved

Javascript prototype problem

Posted on 2014-03-24
5
183 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

762 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

13 Experts available now in Live!

Get 1:1 Help Now