/ cloudformation-templates / node_modules / aws-cdk / node_modules / es5-ext / lib / Object / is-callable.js
is-callable.js
1 // Inspired by: http://www.davidflanagan.com/2009/08/typeof-isfuncti.html 2 3 'use strict'; 4 5 var forEach = Array.prototype.forEach.bind([]); 6 7 module.exports = function (obj) { 8 var type; 9 if (!obj) { 10 return false; 11 } 12 type = typeof obj; 13 if (type === 'function') { 14 return true; 15 } 16 if (type !== 'object') { 17 return false; 18 } 19 20 try { 21 forEach(obj); 22 return true; 23 } catch (e) { 24 if (e instanceof TypeError) { 25 return false; 26 } 27 throw e; 28 } 29 };