Handling null and undefined
#26
Closed
richardboehme
started this conversation in
General
Replies: 1 comment 9 replies
-
As a third option, I've added It would allow you to write null/undefined check by: JS_NULL = JS.eval("return null")
JS_UNDEFINED = JS.eval("return undefined")
if js_value == JS_NULL
puts "null"
elsif js_value == JS_UNDEFINED
puts "undefined"
endDoes it make sense to you? |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
Currently it's not possible to determine if a
JS::Objectwrappingnullorundefinedisnull/undefined. The method for checking other types (JS#is_a?) does not work on those types.I think there are two options for handling this situation:
nullto Rubyniland fixJS#is_a?forundefined.JS#is_a?fornullandundefinedand keep both wrapped in aJS::Object.I personally think the advantage of 1. is that you can write code like:
However
undefinedis also used by a lot of JS code and you would still have to write code like this:The advantage of the second approach is that both cases are handled in the same way. However
JS.global[:null]is not defined so we'd have to define what value to pass intoJS#is_a?.What are your opinions on this?
Beta Was this translation helpful? Give feedback.
All reactions