Joe Honton
Apr 15, 2021

--

I've been relying on .constructor.name since 2015. Here's the repo: https://github.com/joehonton/expect

And here's how I use it:

// ECMAScript types

var alpha = '';

var num = 1;

var obj = {};

var arr = [];

var date = new Date();

var func = function (){};

var regex = /test/i;

var bool = true;

var nullvar = null;

var undef = undefined;

// User-defined types

class Complex {};

class MoreComplex extends Complex {};

var complex = new Complex();

var moreComplex = new MoreComplex();

var unassigned;

// Usage

expect(alpha, 'String');

expect(num, 'Number');

expect(obj, 'Object');

expect(arr, 'Array');

expect(date, 'Date');

expect(func, 'Function');

expect(regex, 'RegExp');

expect(bool, 'Boolean');

expect(nullvar, 'null');

expect(undef, 'undefined');

expect(complex, 'Complex');

expect(moreComplex, 'MoreComplex');

--

--

Joe Honton
Joe Honton

Written by Joe Honton

Princeps geographus, Read Write Tools

No responses yet