Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
subtleGradient / commonjs_app.js
Created January 4, 2010 14:49
CommonJS: Module instances of global objects share prototypes?
var myString1 = require('commonjs_mod').myString;
var myString2 = "app";
myString1.foo(); // no Fail. This string is an instance of a String whose prototype has a `foo` method
myString2.foo(); // Fail. This string is an instance of the global String native
@subtleGradient
subtleGradient / commonjs_app.js
Created January 4, 2010 14:51
CommonJS: Module instances of global objects share prototypes?
String.prototype.foo = function(){ return "foo'd"; };
var myString1 = require('footools').myString;
var myString2 = "app";
myString1.foo(); // Fail?
myString2.foo(); // no Fail
"app".foo(); // Fail. The method `foo` doesn't exist
require('commonjs_mod'); // Modifies the String native
"app".foo(); // no Fail. The method `foo` was added
var Moo = function(){
var context = this;
var Class = this.Class = function(){};
this.String.prototype.foo = function(){ return "foo'd"; };
context.String.prototype.bar = function(){ return "bar'd"; };
};
@subtleGradient
subtleGradient / Function.prototype.startsWith.js
Created January 6, 2010 03:42
Workaround for .NET breaking on `clientID.startsWith`
// Workaround for .NET breaking on `clientID.startsWith`
// Name: MicrosoftAjaxWebForms.debug.js
// Assembly: System.Web.Extensions
// Line: 722
// Error: Object doesn't support this property or method
/*
function Sys$WebForms$PageRequestManager$_matchesParentIDInList
// Wrap all of MooTools code in a function
/*<b support="CommonJS Modules namespace">*/var MooTools = function(exports){/*</b>*/
// fallback exports to `this` so that it can be used as both:
// `MooTools.apply(context)`
// this is the only style that'll work in CommonJS since exports can't be a function
// `MooTools(context)`
// `MooTools()`
if (typeof exports == 'undefined') exports = this;
var context = exports;
/*=
name: Class
description: Code with Class
requires: Accessor
=*/
MooTools.define(function(){
var Class = this.Class = new Type('Class', function(params){
require('MooTools').apply(global); // extends natives; extends global
require('Class').setup.apply(global); // extends global
@subtleGradient
subtleGradient / BuildSugar.SubtleGradient.js
Created January 15, 2010 12:34
BuildSugar—Provides a bizarrely clean & simple syntax sugar for building HTML/XML strings
/*
---
provides : BuildSugar
version : 0.1alpha1
description : Provides a bizarrely clean & simple syntax sugar for building HTML/XML strings
source : http://gist.github.com/278016
git : git://gist.github.com/278016.git
demo : http://jsfiddle.net/SubtleGradient/4W3RR/
author : Thomas Aylott
@subtleGradient
subtleGradient / evalWith.js
Created January 18, 2010 04:39
Dynamic Namespace Localization
function evalWith(namespaces, code){
if ({}.toString.call(namespaces) != '[object Array]')
namespaces = [namespaces];
var imports = {
require: function(){},
exports: {},
module: {}
};