Your api should accept a.

 
Dacamara: Are there any other _safe_ ways to check if an argument is really an object?

Schwimmer: Arg && typeof arg === “object” typeof arg === “function”

Schrecengost: Manuelbieh: Got that?

Jacobson: If that expression is true, then the argument is a non-null object of some kind.

Neathery: Which is not really shorter than checking for typeof undefined and arg !== null. but yes. that works

Pineo: An expression is “falsy” if it is undefined, null, 0, NaN or an empty string.

Glawe: But an empty string object wrapper is truthy.

Schimming: Manuelbieh you can also do if spec === Objectspec

Maschak: Oh, forgot about that.

Ruzich: Ah, great idea. i think that’s the solution i was looking for ;

Schimming: But this creates an allocation on memory so it’s more expensive

Leuty: Manuelbieh, my expression is more longwinded, but less expensive. In fact.

Schimming: Unless it is in fact an object

Schimming: Then it returns the same object

Fugitt: Var type; if arg && type = typeof arg === “object” type === “function” { .

Berardi: I just cache the type check.

Silvano: Not sure if that makes a performance difference though.

Schimming: Typeof is extremely inexpensive

Madariaga: So. typeof arg === “object” typeof arg === “function” // really makes no difference?

Souhrada: Over caching the type check?

Spuler: Why would you ever need to cache a type check?

Rohner: Because I don’t know *what* overhead is involved.

Spuler: That means in practice it doesn’t matter

Steffenson: But caching to a variable would also be O1?

Niebyl: So it makes no real difference.

Spuler: So there is at most a constant difference between them

Straight: Gilgameshkun: if you don’t know what overhead is involved, pretend there is none

Straight: Until you have proof there’s a problem, there isn’t one :-

Spuler: If the constant was large, obviously the engine would cache it for you

Mcmillin: But Object.prototype.toString.callarg.slice8, -1 *is* something I’d cache, even briefly. :3

Spuler: It might be something you should name

Gellings: I tend to wrap it in a function called objectTypeOf

Straight: Gilgameshkun: in ES6 it’s not reliable, so there’s no point in doing that anymore

Spuler: But thinking that you need to cache it is making the wrong consideration the primary one

Straight: Gilgameshkun: because of Symbol.toStringTag

Straight: Gilgameshkun: var obj = {Symbol.toStringTag: ‘Array’}; Object.prototype.toString.callobj === Object.prototype.toString.call will be true.

Straight: Gilgameshkun: what are you checking for? i’ll show you a module that does it safely.

Wiand: Good solution. thanks :

Mcmasters: Object, Array, Function, Uint8Array, etc.

Lindberg: I’d like to see that module.

Straight: Gilgameshkun: right, so. Array.isArray for arrays

Straight: Gilgameshkun: foo && typeof foo === ‘object’ for objects

Straight: Gilgameshkun: https://npmjs.com/is-callable for functions

Straight: Gilgameshkun: and typed arrays have an isArray too iirc

Lecorchick: I want to know a reliable way to retrieve cl*** names of built-in types.

Straight: There isn’t one anymore.

Straight: Https://www.npmjs.com/package/is-string for strings, etc

Straight: Gilgameshkun: the committee doesn’t want people doing that. so, there’s no way to do it in the language anymore.

Straight: You shouldn’t need to do it in a generic way tho

Straight: Your api should accept a thing, say, “is it this specific thing”, else throw