Skip to content

Instantly share code, notes, and snippets.

Element.Storage = {
UID: 1
};
Element.addMethods({
getStorage: function(element) {
if (!(element = $(element))) return;
if (Object.isUndefined(element._prototypeUID))
element._prototypeUID = Element.Storage.UID++;
@cowboy
cowboy / is-this-partial-application.js
Created September 16, 2010 20:26
Is this partial application? Currying? Something else? Vindaloo maybe?
// See my blog post:
// http://benalman.com/news/2010/09/partial-application-in-javascript/
// In the following code sample, invoking the curried function will always
// return a function until all arguments are satisfied, at which point the
// original function is invoked, returning its result. This means that all
// function arguments are required, which also allows the function to be
// called either like foo( 1, 2, 3 ) or foo( 1 )( 2 )( 3 ). This also means
// that if any argument is omitted, the original function is never invoked.
@grignaak
grignaak / coffee.js
Created March 10, 2011 23:08
A requireJS plugin to load CoffeeScript
(function() {
var origDefine = define;
function redefine(name, definitions) {
return function (prereqs, definition) {
if (arguments.length > 2) {
throw new Error('Cannot have more than two arguments to define in ' + name);
} else if (arguments.length === 1) {
definition = prereqs;
prereqs = [];
(function($){
$(function(){
$.support.fixedPosition = (function(){
var container = document.body;
if (document.createElement && container && container.appendChild && container.removeChild) {
var el = document.createElement('div');
if (!el.getBoundingClientRect) return null;
@netroy
netroy / 000-lessthan140chars.js
Created March 31, 2011 11:16
A small template rendering engine in JS ... uses Function constructor, unfortunately
function(b,c){return b.replace(/{[\w\.\(\)]+}/g,function(a){a=a.replace(/[\{\}]/g,"");try{with(c)return eval(a)}catch(b){return""}})};
@DanHulton
DanHulton / gist:993415
Created May 26, 2011 15:58 — forked from hashmal/gist:803816
Playing with CoffeeScript, do funny things with mixins.
# Swappable Mixins in CoffeeScript
# ================================
# Many thanks to Hashmal, who wrote this to start.
# https://gist.github.com/803816/aceed8fc57188c3a19ce2eccdb25acb64f2be94e
# Usage
# -----
# class Derp extends Mixin
@rwaldron
rwaldron / clone.js
Created June 5, 2011 20:30
Real, deep copied objects.
function clone( obj ) {
var val, length, i,
temp = [];
if ( Array.isArray(obj) ) {
for ( i = 0, length = obj.length; i < length; i++ ) {
// Store reference to this array item's value
val = obj[ i ];
// If array item is an object (including arrays), derive new value by cloning
@3rd-Eden
3rd-Eden / factory.js
Created June 20, 2011 18:38
XHR request factory, only does the feature detection once and generates a dedicated function
util.request = (function(){
var fn = {
body: 'return null'
};
if ('XDomainRequest' in window){
fn.body = 'return new XDomainRequest();';
fn.xdomain = true;
} else if ('XMLHttpRequest' in window) {
fn.body = 'return new XMLHttpRequest();';
@jrburke
jrburke / nulleval.js
Created August 17, 2011 20:58
(null,eval)('')
//Came across this in the es-discuss list, on the "clean scope" thread:
https://mail.mozilla.org/pipermail/es-discuss/2011-August/thread.html#16294
//I do not understand what the "null," part buys.
//Has to do something with scope(?), but at least in Firebug,
//I can see foo inside the string being evaled.
var foo = 'foo';
(null,eval)('(function(){console.log(foo);}())');
@mattpodwysocki
mattpodwysocki / jsconf-eu-2011.md
Created October 1, 2011 13:40
JSConf.EU Slides