7

how can I check if the result to call a JavaScript function is undefined?

I tried with

if( s.getNode(id1) != js.undefined) 

but fastOptJS say:

scala.scalajs.js.Dynamic and scala.scalajs.js.UndefOr[Nothing] are unrelated: they will most likely always compare unequal

TIA

Saagar Elias Jacky
  • 2,684
  • 2
  • 14
  • 28
gilcu2
  • 343
  • 3
  • 13

1 Answers1

12

This is Scala's type system being a bit "too" helpful.

To compare against undefined, you can use js.isUndefined:

if (!js.isUndefined(s.getNode(id1)))
sjrd
  • 21,805
  • 2
  • 61
  • 91
  • Thanks very much. Where is it documented? I can see it in http://www.scala-js.org/api/scalajs-library/0.6.2/#scala.scalajs.js.package – gilcu2 Apr 29 '15 at 09:49
  • 2
    Now it's documented here ;-) If you think there is a logical place to document this, besides the API, we can add it. But it seems like a "troubleshooting" kind of documentation, for which an SO entry is likely to be the best documentation ever. – sjrd Apr 29 '15 at 12:02
  • Sorry, I wanted to say I can't see it in .... If it is in the documentation I can't find it but that is my problem them. Thanks – gilcu2 Apr 29 '15 at 18:12
  • 1
    On the very page you mention: http://www.scala-js.org/api/scalajs-library/0.6.2/index.html#scala.scalajs.js.package@isUndefined%28v:Any%29:Boolean – sjrd Apr 29 '15 at 18:26
  • Sorry, my eyes problem. Thanks for all – gilcu2 Apr 29 '15 at 18:35