-
Notifications
You must be signed in to change notification settings - Fork 7.3k
vm instanceof operator don't work as expected #1277
Comments
Not a bug. New context and old context have each their own, distinct, Array object. |
Yes. Not sharing the global builtins is the point of running in a new context ;) If you want to share specific globals, you can do it this way: vm.runInContext("a instanceof Array", vm.createContext({a:[], Array:Array})) EDIT I guess this way is easier, and closer to the original code: vm.runInNewContext("a instanceof Array", {a:[], Array:Array}) |
But if it is about (cross-context) Array testing, Array.isArray(a) is the way to go (unless I am mistaken, but I was told it works over context boundary as well). |
Yes, Array.isArray() is the best way to test if something is an array. |
Thank you very much people, that clears my trouble :) |
Consider the following: https://github.com/visionmedia/express/blob/master/lib/router/route.js#L71
One work-around is passing
but is there a way to make it work with literals? |
@bpaf: Like this?
|
actually there seems to be a bug here, node does not use the RegExp object passed in the context to create regexp objects from regexp literals. |
@brokendroid: To quote the Zen of Python, explicit is better than implicit. |
Works as designed.
Same as the Array case. |
The following code returns false
The text was updated successfully, but these errors were encountered: