Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
subtleGradient / Class.subclass.moo-future.js
Created February 11, 2010 02:28
mySubClass = MyClass.subclass(function(){ … })
var Person = Class.subclass(function(def, Protected, Generic, Parent){
// Private
// Available to all methods in this definition
var private_variable;
// Protected
// Available to this Class, its instances, all subclasses and all their instances
// Protected methods are bound to each instance
@subtleGradient
subtleGradient / Class.method.moo1.js
Created February 11, 2010 02:26
"method" method mutator
// Current MooTools 1.2 Class subclass syntax
// all methods are wrapped
// to provide protected support
// and `this.parent`
var Dude = new Class({
Extends: Person,
@subtleGradient
subtleGradient / Class.js
Created February 2, 2010 03:12
Mythical constructor-based Class Implementation Syntax idea
// Create a new class by subclassing Class
var MyClass = Class.subclass(function(Public, Private){
Public.implement([Events, Options]);
Public.method = function(arg){
console.log('grand pappy Method!');
};
Public.methodWithAName = methodWithAName;
@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: {}
};
@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
require('MooTools').apply(global); // extends natives; extends global
require('Class').setup.apply(global); // extends global
/*=
name: Class
description: Code with Class
requires: Accessor
=*/
MooTools.define(function(){
var Class = this.Class = new Type('Class', function(params){
// 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;
@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
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"; };
};