This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global){ | |
var setTimeout = global.setTimeout; | |
var clearTimeout = global.clearTimeout; | |
var timeoutIdentityObjects = []; | |
global.setTimeout = function(f, t){ | |
var timeoutIdentityObject = new Object; // Insisting on the object being new and different from all previously generated | |
var i = setTimeout(function(){ | |
f.call(); // Incomplete, because doesn't take strings and optinal arguments into consideration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object.{freeze|seal|preventExtensions}(proxy) -> proxy | |
fix: function() { | |
// As long as target is not frozen, the proxy won't allow itself to be fixed | |
if (!Object.isFrozen(this.target)) | |
return undefined; | |
var props = {}; | |
var handler = this; | |
Object.getOwnPropertyNames(this.target).forEach(function (name) { | |
var desc = Object.getOwnPropertyDescriptor(this.target, name); | |
// turn descriptor into a trapping accessor property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var getInstance = (function(){ | |
var p = Object.create(null); | |
return function(){ | |
return Object.create(p); | |
}; | |
})(); | |
var c1 = getInstance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Proxy.ForwardingHandler.prototype = { | |
/*** | |
** all traps use this.state.get[proxy] to retrieve the target | |
*/ | |
state: new WeakMap(); | |
}; | |
function ForwardingPair(target){// Could be Proxy.ForwardingPair too... | |
var h = new Proxy.ForwardingHandler(); // Just a new object identity inheriting from all methods | |
var p = Proxy.create(h); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var els = document.querySelectorAll('a'); | |
els.forEach(function(e){console.log(e.href);}); // TypeError: els.forEach is not a function | |
// Why? | |
// document.querySelectorAll returns a NodeList. | |
// First thing first, as opposed to other NodeList, this one is not live, mostly because the | |
// implementation of a live object would be terribly complicated for some selectors | |
// NodeList are a DOM interface introduced in DOM core level 1 (random guess) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global){ | |
// Place to store fake arrays | |
var myProxyArrays = new WeakMap(); | |
global.ProxyArray = (function(){ | |
var handler, call, construct; | |
// See https://github.com/DavidBruant/ProxyArray for actual implementation | |
return function(){ | |
var p = Proxy.createFunction(handler, call, construct); // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomColorString(){ | |
var r, g, b; | |
r = Math.floor(256*Math.random()).toString(10); | |
g = Math.floor(256*Math.random()).toString(10); | |
b = Math.floor(256*Math.random()).toString(10); | |
return ('rgb('+ r +','+ g +','+ b +')'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f(){} | |
var g = f.bind({}); | |
var newg = new g; | |
// call g.[[Construct]] (which is f.[[Construct]] per ES5.1 15.3.4.5 step 13) | |
// so, |new g| is the same as |new f|: an object which has f.prototype as [[Prototype]] | |
newg instanceof g; | |
// instanceof g calls the g.[[HasInstance]](newg) (please forgive my skip of reference/GetValue mess) | |
// As per ES5.1 - 15.3.4.5.3, g.[[HasInstance]](V) is g.[[TargetFunction]].[[HasInstance]](V) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keys = []; | |
var n; | |
var P = Object.getPrototypeOf; | |
var o = window; | |
// Retrieving all property names of the global object, | |
// because proto chain are messy and different in all browsers | |
while(o !== null){ | |
keys = keys.concat(Object.getOwnPropertyNames(o)); | |
o = P(o); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var links = document.getElementsByTagName('a'); | |
console.log(links.length); | |
var workingUrls = [], | |
brokenUrls = []; | |
function l(e){ | |
var t = e.target; | |
var url = t.src; | |
console.log(url, e.type); |
OlderNewer