繁体   English   中英

“instanceof Date”在 BigQuery UDF 中的行为不符合预期

[英]`instanceof Date` not behaving as expected within a BigQuery UDF

任何人都知道为什么以下结果是false而不是true

CREATE TEMPORARY FUNCTION test()
RETURNS BOOL
LANGUAGE js
AS
"""
const d = new Date();
return d instanceof Date;
""";
SELECT test();

返回false (意外)


解决方法:

CREATE TEMPORARY FUNCTION test()
RETURNS BOOL
LANGUAGE js
AS
"""
const d = new Date();
return Object.prototype.toString.call(d) === '[object Date]';
""";
SELECT test();

返回true (如预期)

instanceof Date接缝不起作用。

对于其他对象,如String ,它工作正常。

有一个 JavaScript 解决方法

CREATE TEMPORARY FUNCTION test()
RETURNS  BOOL
LANGUAGE js
AS
"""
var  d = new Date();
var s= new String('String created with constructor');
//return s instanceof String;
return typeof d.getMonth === 'function';
""";

SELECT test();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM