Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This:</p> <pre><code>alert(Number(String(foo)) * 2); </code></pre> <p>should do it (but <strong>see below</strong>), if your COM object implements <code>toString</code> (or <code>valueOf</code> with the "string" hint) correctly (and apparently it does, if your <code>innerHTML</code> trick works -- because when you assign <code>foo</code> to <code>innerHTML</code>, the same process of converting the COM object to a string occurs as with <code>String(foo)</code>).</p> <p>From Section 15.5.1 of the 5th Edition ECMAScript spec:</p> <blockquote> <p>When String is called as a function rather than as a constructor, it performs a type conversion.</p> </blockquote> <p>And Section 15.7.1</p> <blockquote> <p>When Number is called as a function rather than as a constructor, it performs a type conversion</p> </blockquote> <p>It may be worth trying just <code>Number(foo) * 2</code> to make sure, but I don't think it'll work (it seems like your COM object only handles conversion to String, not Number, which isn't surprising or unreasonable).</p> <hr> <p><strong>Edit</strong> If <code>String(foo)</code> is failing, try:</p> <pre><code>alert(Number("" + foo) * 2); </code></pre> <p>I'm <strong>very</strong> surprised that your <code>innerHTML</code> trick is working but <code>String(foo)</code> is throwing an error. Hopefully <code>"" + foo</code> will trigger the same <em>implicit</em> conversion as your <code>innerHTML</code> trick.</p> <hr> <p><strong>Edit</strong> Okay, this COM object is being very strange indeed. My next two salvos:</p> <pre><code>alert(("" + foo) * 2); </code></pre> <p>That uses all implicit conversions (adding an object to a string converts the object to a string; applying the <code>*</code> operator to a string converts it to a number).</p> <p>Alternately, we can make the string->number conversion explicit but indirect:</p> <pre><code>alert(parseInt("" + foo) * 2); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload