phpjs
Version:
16 lines (15 loc) • 562 B
JavaScript
function is_resource(handle) {
// From: http://phpjs.org/functions
// + original by: Brett Zamir (http://brett-zamir.me)
// + improved by: Luis Salazar (http://www.freaky-media.com/)
// * example 1: is_resource('a');
// * returns 1: false
var getFuncName = function(fn) {
var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
if (!name) {
return '(Anonymous)';
}
return name[1];
};
return !(!handle || typeof handle !== 'object' || !handle.constructor || getFuncName(handle.constructor) !== 'PHPJS_Resource');
}