It's a generally known problem is JavaScript that "instanceof" doesn't
work across contexts (not just the vm module). This is even a problem
in the web browser. So JS devs have had to come up with a sure-fire
way to determine if you have a Date object by checking the internal
[[Class]] property, which would be "Date" in the case of a Date.
util.isDate's source code looks something like:
util.isDate = function (d) {
return Object.prototype.toString.call(d) === '[object Date]';
}
Hope that helps!
On Sun, Mar 11, 2012 at 10:02 AM, Mark Volkmann
<[email protected]> wrote:
> On Sun, Mar 11, 2012 at 11:39 AM, Jann Horn <[email protected]> wrote:
>> Am Sonntag, den 11.03.2012, 11:10 -0500 schrieb Mark Volkmann:
>>> util.isDate(obj)
>>>
>>> obj instanceof Date
>>
>>> new Date() instanceof Date
>> true
>>> require('vm').runInNewContext('new Date()') instanceof Date
>> false
>>> require('util').isDate(new Date())
>> true
>>> require('util').isDate(require('vm').runInNewContext('new Date()'))
>> true
>
> Thanks for that example! It does seem like an obscure case though
> since the vm module isn't heavily used module. You could also put the
> Date constructor into the context so instanceof would work.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en