UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

84 lines (70 loc) 2.29 kB
--- layout: page title: "JavaScript is_object function" comments: true sharing: true footer: true alias: - /functions/view/is_object:450 - /functions/view/is_object - /functions/view/450 - /functions/is_object:450 - /functions/450 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's is_object {% codeblock var/is_object.js lang:js https://raw.github.com/kvz/phpjs/master/functions/var/is_object.js raw on github %} function is_object (mixed_var) { // From: http://phpjs.org/functions // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Legaev Andrey // + improved by: Michael White (http://getsprink.com) // * example 1: is_object('23'); // * returns 1: false // * example 2: is_object({foo: 'bar'}); // * returns 2: true // * example 3: is_object(null); // * returns 3: false if (Object.prototype.toString.call(mixed_var) === '[object Array]') { return false; } return mixed_var !== null && typeof mixed_var === 'object'; } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/var/is_object.js) Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are the closest match to this hashtable-like data structure. Please also note that php.js offers community built functions and goes by the [McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just: - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/var/is_object.js) ### Example 1 This code {% codeblock lang:js example %} is_object('23'); {% endcodeblock %} Should return {% codeblock lang:js returns %} false {% endcodeblock %} ### Example 2 This code {% codeblock lang:js example %} is_object({foo: 'bar'}); {% endcodeblock %} Should return {% codeblock lang:js returns %} true {% endcodeblock %} ### Example 3 This code {% codeblock lang:js example %} is_object(null); {% endcodeblock %} Should return {% codeblock lang:js returns %} false {% endcodeblock %} ### Other PHP functions in the var extension {% render_partial _includes/custom/var.html %}