EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

js类型 #47

Open EdwardZZZ opened 5 years ago

EdwardZZZ commented 5 years ago
const obj = {
    _undefined: void 0,
    _string: 'abc',
    _null: null,
    _int: 1,
    _float: 1.1,
    _bool: true,
    _date: new Date(),
    _function: function() {},
    _object: {},
    _array: [],
    _map: new Map(),
    _set: new Set(),

    _symbol: Symbol(),
    _class: class a{},
    _promise: Promise.resolve(),
    _weakSet: new WeakSet(),
    _weakMap: new WeakMap(),
    _generator: function* g(){},
    _async: async function() {},
    _proxy: new Proxy({}, {}),
    _regexp: new RegExp(),
}

for(let key in obj) {
    const val = obj[key];
    console.log(key, Object.prototype.toString.call(val).slice(8, -1), typeof val);
    console.log('\n');
}
EdwardZZZ commented 4 years ago
VM493:4 _undefined Undefined undefined
VM493:4 _string String string
VM493:4 _null Null object
VM493:4 _int Number number
VM493:4 _float Number number
VM493:4 _bool Boolean boolean
VM493:4 _date Date object
VM493:4 _function Function function
VM493:4 _object Object object
VM493:4 _array Array object
VM493:4 _map Map object
VM493:4 _set Set object
VM493:4 _symbol Symbol symbol
VM493:4 _class Function function
VM493:4 _promise Promise object
VM493:4 _weakSet WeakSet object
VM493:4 _weakMap WeakMap object
VM493:4 _generator GeneratorFunction function
VM493:4 _async AsyncFunction function
VM493:4 _proxy Object object
VM493:4 _regexp RegExp object