currently using:
function isobjliteral(_obj) { var _test = _obj; return ( typeof _obj !== 'object' || _obj === null ? false : ( (function () { while (!false) { if ( object.getprototypeof( _test = object.getprototypeof(_test) ) === null) { break; } } return object.getprototypeof(_obj) === _test; })() ) );
}
to test if we're using object literal. problem ie8< cannot use getprototypeof
, know easy workaround?
improving this workaround:
if (typeof object.getprototypeof !== "function") object.getprototypeof = "".__proto__ === string.prototype ? function (obj) { if (obj !== object(obj)) throw new typeerror("object please!"); return obj.__proto__; } : function (obj) { if (obj !== object(obj)) throw new typeerror("object please!"); // may break if constructor has been tampered var proto = obj.constructor && obj.constructor.prototype; if (proto === obj) { // happens on prototype objects example var cons = obj.constructor; delete obj.constructor; proto = obj.constructor && obj.constructor.prototype; obj.constructor = cons; } // if (proto === obj) return null; // else went wrong return proto; };
haven't tested it, should work in ie8 cases. btw, seems isobjliteral
can simplified to
function isplainobject(obj) { if (obj !== object(obj)) return false; var proto = object.getprototypeof(obj); return !!proto && !object.getprototypeof(proto); }
Comments
Post a Comment