Skip to content

Instantly share code, notes, and snippets.

View kangax's full-sized avatar

Juriy Zaytsev kangax

View GitHub Profile
/*
Checks that `toString` of constructor's prototype has "special" behavior (i.e. is `Object.prototype.toString`) as per 15.2.4.2
Cons:
- Relies on `constructor` property of an object (as well as `toString` of constructor's prototype) being present and not augmented
(will fail on host objects in IE that lack constructor, but could be guarded against)
- Does not differentiate between Object objects created implicitly via function constructor and those created explicitly via Object
Pros:
/* can you spot what is happening here */
/* the alert("X") should never execute */
<script>
onload = function() {
var fn = function() {
alert("X");
}
(function() { })();