google-bigquery - `instanceof Date` 在 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();
推荐阅读
- kubernetes - kubernets pod 在挂载之前使用 configmap
- xamarin.android - 我想用事件制作滑块来捕获 Xamarin.Android 中的值
- sql - 过程问题 SQL Server 出现错误
- android - 创建的工具栏无法在 Android 设备上正确显示
- css - 打字稿的 CSS 界面
- android - 如果在 CoordinatorLayout 中设置了anchorView,则浮动操作按钮不与 Snackbar 一起浮动
- java - 我无法在我的 android 模拟器中接收 Firebase Cloud Messaging FCM
- macos - 如何在 Mac 上安装 Tesseract 5.0.0 alpha?
- c++ - 如何从启动时最大化cpp程序中的窗口?
- windows - 如何通过单击从 Windows 中的 Go 可执行文件打开特定文件