Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript prototype problem

Posted on 2014-03-24
5
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

618 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