Skip to content

Instantly share code, notes, and snippets.

@grid23
grid23 / gist:2479261
Created April 24, 2012 12:31
addEventListener poly
//addEventListener polyfill with e.preventDefault and e.stopPropagation for old IEs
// DO NOT PUT THAT ONE ON GLOBAL SCOPE, just saying... :D
var addEventListener = (function(){
if ( window.addEventListener )
return function(el, ev, fn, c){
return el.addEventListener(ev, fn, !!c)
}
return function(el, ev, fn){
return el.attachEvent('on'+ev, function(e){
/*
CookieList v0.0.3
v0.0.3 changelog :
- a little faster
- detect if cookie is enabled
- polyfill for max-age attribute, so you don't have to care about it yourself
TODO list :
- get faster
@grid23
grid23 / cookieList.js
Last active December 17, 2015 07:58 — forked from rvpouyol/cookieList.js
/*
CookieList v0.0.4
changelog :
0.0.4 : fixes by rvpouyol
- max-age in s, expires in ms
- NO_MAX_AGE_SUPPORT correctly used
TODO list :
- get faster
@grid23
grid23 / object-keys-poly.js
Created June 26, 2013 19:45
Classic Object.keys polyfill with a twist: if an object instance of Arguments get into the function, old IEs will simply ignore the for ( k in arguments ) loop and the polyfill will silently fail... The *only way* to identify an object instance of Arguments in old IEs is to check for the presence of the method callee! If an arguments is detected…
var enumerate = Object.keys || function(o){
var arr = []
, o = !!o.callee ? Array.prototype.slice.call(o) : o
, k
for ( k in o ) if ( arr.hasOwnProperty.call(o, k) )
arr.push(k)
return arr
}
@grid23
grid23 / dunno.js
Last active January 2, 2016 01:19
Am I doing it right ? ;-)
(()=>{ "use strict"
let mixinHandler = {
get: (t, n)=>{
if ( t[n] != void 0 )
return t[n]
for ( let i = t.__parents__.length-1; ~i; i-- )
if ( t.__parents__[i][n] != void 0 )
return t.__parents__[i][n]
@grid23
grid23 / duh.md
Last active August 29, 2015 14:02
"abc".replace(/abc/, "$&") // "abc"
"abc".replace("abc", "$&") // "abc"
"abc".replace("abc", function(){ return "$&" }) //  safari: "abc", others: "$&"
"abc".replace(/abc/, function(){ return "$&" }) // "$&"