[英]`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
,它工作正常。
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.