Uploaded image for project: 'ClojureScript'
  1. CLJS-890

Incorrect behaviour of (str obj) when obj has valueOf method

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: None
    • Labels:
      None
    • Patch:
      Code

      Description

      Example

      (str #js {"toString" (fn [] "hello") "valueOf" (fn [] 42)}) ; => "42"
      

      The problem in the fact that ClojureScript uses concatenation to convert values to strings and that doesn't work well with objects which have valueOf() method overriden.

      Example in js:

      var obj = {
          toString: function() { return 'hello'; },
          valueOf: function() { return 42; }
      };
      console.log(String(obj)); => 'hello'
      console.log(obj.toString()); => 'hello'
      console.log('' + obj); => '42'
      

      Potential solution might be to use String() function. Using toString() won't work as described in this issue: http://dev.clojure.org/jira/browse/CLJS-847

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              nbeloglazov Nikita Beloglazov
            • Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated: