Skip to content

Instantly share code, notes, and snippets.

@rozek rozek/asString.js
Created Sep 5, 2018

Embed
What would you like to do?
asString: convert Object.create(null) to string
/**** asString - can also convert Object.create(null) to string ****/
asString = function asString (Value) {
switch (Value) {
case undefined: return '[object Undefined]';
case null: return '[object Null]';
default:
if (Array.isArray(Value)) { return '[object Array]' };
return (
(typeof Value === 'object') && (Object.getPrototypeOf(Value) == null)
? '[object]'
: String(Value)
);
};
};
@rozek

This comment has been minimized.

Copy link
Owner Author

rozek commented Sep 5, 2018

I recently learned that calling String(Object.create(null)) throws an error under JavaScript.

Now I have to check my existing JS code and see whether there are any string conversion of the kind "String(...)" and replace them by "asString(...)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.