Loading ...
Sorry, an error occurred while loading the content.

1155Re: I must use 'new String'

Expand Messages
  • walfisch_in_the_sea
    Feb 17, 2010
    • 0 Attachment
      Or:

      var string = {
      toString: function () {
      return "The actual String";
      },
      id: 123
      };

      alert(string);
      alert(string.id);




      --- In jslint_com@yahoogroups.com, Klemen Slavič <krof.drakula@...> wrote:
      >
      > Why not use JSON to carry values in such a case?
      >
      > var a = {
      > value: "somestring",
      > id: 123
      > };
      >
      > On 17 February 2010 14:04, Harry Whitfield <g7awz@...> wrote:
      >
      > >
      > >
      > >
      > > On 17 Feb 2010, at 12:38:45, Jakob Kruse wrote:
      > >
      > > > What's wrong with
      > > >
      > > > var str = "somestring";
      > > > str.id = 123;
      > > >
      > > > ?
      > > >
      > > > /Jakob
      > >
      > > Running the following code in Widget Tester:
      > >
      > > var str1 = "something";
      > > print("typeof str1: " + typeof str1);
      > > var str2 = new String("anything");
      > > print("typeof str2: " + typeof str2);
      > > str1.id = 123;
      > > print("str1.id === undefined: " + (str1.id === undefined));
      > > print("str1.id: " + str1.id);
      > > str2.id = 456;
      > > print("str2.id === undefined: " + (str2.id === undefined));
      > > print("str2.id: " + str2.id);
      > >
      > > produces this output:
      > >
      > > typeof str1: string
      > > typeof str2: object
      > > str1.id === undefined: true
      > > str1.id: undefined
      > > str2.id === undefined: false
      > > str2.id: 456
      > >
      > > Harry.
      > >
      > >
      > >
      >
      >
      > [Non-text portions of this message have been removed]
      >
    • Show all 15 messages in this topic