Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<!-- Online here: -->
li { background: green; } li.FAIL { background: red; }
iframe { display: none; }
<ul id="results"></ul>
function isObjectLiteral(obj){
// Implement me!
return false;
// Other Solutions:
// Uses function serialization which doesn't work in all browsers
//return /^function Object/.test( obj.constructor );
// Doesn't work with object from other windows
//return === "[object Object]";
// Function serialization is not permitted
// Does not work across all browsers
Function.prototype.toString = function(){};
log("{}", {}, true);
log("new Date", new Date, false);
var fn = function(){};
log("fn", fn, false);
log("new fn", new fn, false);
var iframe = document.createElement("iframe");
var doc = iframe.contentDocument || iframe.contentWindow.document;;
doc.write("<body onload=';'>");
function iframeDone(otherObject){
log("new otherObject", new otherObject, true);
function log(msg, a, b) {
var pass = isObjectLiteral(a) === b ? "PASS" : "FAIL";
document.getElementById("results").innerHTML +=
"<li class='" + pass + "'>" + msg + "</li>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment