Skip to content

Instantly share code, notes, and snippets.

View z2015's full-sized avatar
🎯
Focusing

William Zhou z2015

🎯
Focusing
View GitHub Profile
@z2015
z2015 / iframe-memory-leak-prevention.html
Created March 14, 2017 02:39 — forked from hallettj/iframe-memory-leak-prevention.html
iFrame memory leak prevention test
<!doctype html>
<html>
<head>
<title>iFrame memory leak prevention test</title>
</head>
<body>
<h1>iFrame memory leak prevention test (void)</h1>
<p>In IE up through version 8 adding an iframe to a page and
removing it produces a memory leak in some cases. The pattern
@z2015
z2015 / flyweight.js
Created May 20, 2016 02:16 — forked from addyosmani/flyweight.js
The Flyweight pattern
// Flyweight.js - Copyright Addy Osmani, 2012.
// Consider public domain
// My implementation in JS of this:
// http://en.wikipedia.org/wiki/Flyweight_pattern
// Simulate pure virtual inheritance/'implement' keyword for JS
Function.prototype.implementsFor = function (parentClassOrObject) {
if (parentClassOrObject.constructor == Function) {
// Normal Inheritance
this.prototype = new parentClassOrObject;
/**
Code copyright Dustin Diaz and Ross Harmes, Pro JavaScript Design Patterns.
**/
// Constructor.
var Interface = function (name, methods) {
if (arguments.length != 2) {
throw new Error("Interface constructor called with " + arguments.length + "arguments, but expected exactly 2.");
}
this.name = name;
@z2015
z2015 / pubsub.md
Created May 11, 2016 02:00 — forked from addyosmani/pubsub.md
Four ways to do Pub/Sub with jQuery 1.7 and jQuery UI (in the future)

#Four Ways To Do Pub/Sub With jQuery and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

@z2015
z2015 / formData.js
Created May 9, 2016 07:55 — forked from anonymous/formData.js
Add blob filt to FormData
formData.append(name, value);
formData.append(name, value, filename);
//https://developer.mozilla.org/en-US/docs/Web/API/FormData/append
//The filename reported to the server (a USVString), when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.