Skip to content

Instantly share code, notes, and snippets.

@jaubourg
jaubourg / typeOf.js
Created February 16, 2010 10:18 — forked from rkatic/README.md
(function($){
var toString = Object.prototype.toString;
var class2type = {
"[object Boolean]": "boolean",
"[object Number]": "number",
"[object String]": "string",
"[object Function]": "function",
"[object Array]": "array",
<?php
## Nav data, as a JSON heredoc. Much less verbose than PHP arrays!
$navs = json_decode(<<<JSON
{
"mlb": {
"title_link": "http://stats.boston.com/mlb/scoreboard.asp",
"nav": [
{ "title": "Full Schedule", "url": "http://stats.boston.com/mlb/teamreports.asp?tm=02&report=schedule" },
{ "title": "Statistics", "url": "http://stats.boston.com/mlb/teamreports.asp?yr=2009&tm=2&btnGo=Go&report=stats" },
// Create type-related methods:
// isArray, isBoolean, isDate, isFunction, isObject, isNumber, isRegExp, isString and type
jQuery.isFunction = jQuery.noop;
jQuery.each( "Array Boolean Date Function Object Number RegExp String ".split(" "), function( lName, name ) {
lName = class2type[ "[object " + name + "]" ] = name.toLowerCase();
jQuery[ name ? ( "is" + name ) : "type" ] = nativeTypeTests[ name ] || function( value ) {
value = value == null ?
String( value ) :
class2type[ toString.call( value ) ] || "object";
return name ? ( value === lName ) : value;
@jaubourg
jaubourg / gist:948434
Created April 29, 2011 15:09 — forked from danheberden/gist:948429
making $.when() always report one arg
var getName = (function() {
var cache; // private cache
// gets assigned to getName
return function() {
// return the cache if it's valid or
return cache || $.ajax({
url: 'srv/echo',
@jaubourg
jaubourg / gist:1138463
Created August 10, 2011 22:33
jQuery boilerplate suggestion
// remember to change every instance of "pluginName" to the name of your plugin!
// the semicolon at the beginning is there on purpose in order to protect the integrity of your scripts when
// mixed with incomplete objects, arrays, etc.
;(function( $ ) {
// plugin's default options
// this is private property and is accessible only from inside the plugin
var defaults = {
propertyName : 'value'
};
@jaubourg
jaubourg / Events.js
Created November 23, 2011 00:37 — forked from DaveStein/Events.js
Singleton wrapper around $.Callbacks to emulate Backbone events
var Event = (function( $ ) {
var cache = {},
slice = [].slice,
fake = {
remove: $.noop,
fireWith: $.noop
};
function get( ev, createIfNeeded ) {
@jaubourg
jaubourg / InlineWorker.js
Last active October 13, 2015 10:08
Create a Web Worker from a function, not a file
// Web Workers can be built from data URLs!
// See http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#dom-worker
// Chrome doesn't seem to support this yet but FF does
// So how about a helper to create a Web Worker from a function
var InlineWorker = (function() {
var r_func = /^\s*function\s*\(.*?\)\s*\{|\}\s*$/g;
Hello World
Hello World