You are not logged in.
Login
or
Register
.
JsPHP: a JavaScript library providing the PHP API
Home
Register
Demo
Categories
Functions
Contributors
Download
Links
Comments
FAQ
Contact
View
Edit
Benchmark
Revisions
Developers
Dependencies
Talk
Links
get_class:
Edit: get_class
Function:
get_class
View get_class
Edit get_class
Edit code
Edit tests
Edit benchmark
View latest code
Edit latest code
Benchmark get_class
Comment on get_class
Comment on the latest code
View revisions
View versions
View contributors
View dependencies
View comments
View links
Download production code
Download development code
View the PHP docs
View phpjs.org
View phpjs.org raw code
Description:
Retrieves the class name.
Edit function
Code
:
function get_class (obj) { // http://jsphp.co/jsphp/fn/view/get_class // + original by: Ates Goral (http://magnetiq.com) // + improved by: David James // + improved by: David Neilsen // * example 1: get_class(new (function MyClass() {})); // * returns 1: "MyClass" // * example 2: get_class({}); // * returns 2: "Object" // * example 3: get_class([]); // * returns 3: false // * example 4: get_class(42); // * returns 4: false // * example 5: get_class(window); // * returns 5: false // * example 6: get_class(function MyFunction() {}); // * returns 6: false if (obj && typeof obj === 'object' && Object.prototype.toString.call(obj) !== '[object Array]' && obj.constructor && obj !== this.window) { var arr = obj.constructor.toString().match(/function\s*(\w+)/); if (arr && arr.length === 2) { return arr[1]; } } return false; }
You have to be logged in to edit functions.
[
top
]
Comments
There are no comments yet, be the first!
Please
Login
or
Register
to post comments.