Skip to content

Instantly share code, notes, and snippets.

@MaraScott
Last active December 11, 2015 08:09
Show Gist options
  • Save MaraScott/4571536 to your computer and use it in GitHub Desktop.
Save MaraScott/4571536 to your computer and use it in GitHub Desktop.
Name : isOneOf(obj, types) - Language : JavaScript - type : function - platform : generic
// http://stackoverflow.com/questions/8525206/javascript-the-most-efficient-way-to-check-if-a-variable-is-a-function-an-arra?answertab=votes#tab-top
function isOneOf(obj, types) {
"use strict";
var type;
type = Object.prototype.toString.call(obj);
return types.split(' ').some(function (t) {
return type.indexOf(t) > -1;
});
}
isOneOf({}, 'Array Object Function');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment