Javascript 当变量类型为';存储为字符串还是布尔值?
Mongoose让您输入字段类型,如Javascript 当变量类型为';存储为字符串还是布尔值?,javascript,node.js,function,mongoose,types,Javascript,Node.js,Function,Mongoose,Types,Mongoose让您输入字段类型,如String、Boolean、Number等,这些都是函数。我想将这些值作为字符串读取,以便将它们用作对象键。如何从字符串中获取“字符串”,从布尔值中获取“布尔值” var Model = { name: String, likes: Number }; console.log('the type of name is '+Model.name) 这当然会打印出如下内容: the type of name is function Strin
String
、Boolean
、Number
等,这些都是函数。我想将这些值作为字符串读取,以便将它们用作对象键。如何从字符串中获取“字符串”,从布尔值中获取“布尔值”
var Model = {
name: String,
likes: Number
};
console.log('the type of name is '+Model.name)
这当然会打印出如下内容:
the type of name is function String() {
[native code]
}
因为我引用的是一个函数函数对象有一个,它以字符串形式返回函数名
for(常数fn of[
字符串,/“字符串”
布尔值,/“布尔值”
编号,/“编号”
函数foo(){},//“foo”
类bar{},//“bar”
() => {}, //""
新函数(“”,//“匿名”
])console.log(fn.name)
type of Model.name