我正在尝试获取对象的基本类型但失败了。Chrome 的控制台似乎可以做到,但我做不到。
这是控制台给我的:
我试图以Blockly.FieldDropdown
某种方式得到。
Chrome 控制台如何能够找到它,但我不能?
该对象由 Google Blockly 返回:
var block = Blockly.mainWorkspace.getBlockById(e.blockId);
var field = block.getField(inputId); //field is the object shown in console above...
或者作为一个独立的工作示例:
var field = new Blockly.FieldDropdown([['left', 'LEFT'], ['right', 'RIGHT']]);
// these return an empty string, but I'd like to get back "Blockly.FieldDropdown"
console.log(Object.getPrototypeOf(field).constructor.name);
console.log(field.__proto__.constructor.name);
// the following shows "Blockly.FieldDropdown" in front of the properties
// in Chrome's dev console (but not in Firefox for example,
// and the name is not accessible):
// console.log(field);
<script src="https://cdn.jsdelivr.net/npm/blockly@3.20191014.3/blockly.min.js"></script>
我试过找到一个返回类型的 Blockly 方法,但我还没有看到。