Announcement

Collapse
No announcement yet.

main() parameters - strings forced to numbers?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • main() parameters - strings forced to numbers?

    Hi

    I have some function parameters that are .STRING, but are numeric, like:
    PHP Code:
            fpArray[x] = new FunctionParameter("sPeriod2"FunctionParameter.STRING);
    ...
        
    with (fp) {
               
    addOption("3");
    ... 
    In main() I find I have to do this:

    PHP Code:
                if (typeof(sPeriod2) == "number") { 
                    
    sPeriod2 sPeriod2.toString();
                } 

    Is this a bug?

  • #2
    -

    Hello Dave,

    JavaScript is a dynamically typed language (see Data Type Conversion), which will automatically convert a string representation of a number to a number type. The .setDefault() method of the FunctionParameter class was changed at one point to force the value to remain a string, but the .addOption() method was not modified. I believe this was due to backward compatibility reasons. If you want to use numbers as strings with the FunctionParameter.STRING type, you will need to use a custom work-around as you are.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Jason, Hi, "dynamically typed" yes, but when needed I thought. Just passing an argument to a function does not change the type. Perhaps the docs should note this oddity?

      Comment

      Working...
      X