Skip to content

Instantly share code, notes, and snippets.

View zhuzhuaicoding's full-sized avatar

zhuzhu_coder zhuzhuaicoding

View GitHub Profile
@zhuzhuaicoding
zhuzhuaicoding / gist:1433092
Created December 5, 2011 10:04 — forked from elijahmanor/gist:589968
Use === and !==
// Use === and !==
// It is often better to use the === and !== operators
// rather than == and != operators. The reason for this
// is that === and !== (also known as the identity operators)
// check for the type as well as the value when being compared
// whereas the == and != will try to coerce the two values
// into the same type before the comparison is made, which
// may lead to some very unexpected results.
@zhuzhuaicoding
zhuzhuaicoding / gist:1433097
Created December 5, 2011 10:07 — forked from elijahmanor/gist:590041
Prevent Default Behavior
// Prevent Default Behavior
// 'return false' stops the default behavior of the event
// and prevents it from bubbling up DOM, which kills
// event delegation and may not be what you indented.
// You might consider using e.preventDefault() or
// e.stopPropagation() instead
//event.preventDefault()
//Event Delegation Friendly
@zhuzhuaicoding
zhuzhuaicoding / jquery.ba-tinypubsub.js
Created March 2, 2012 23:15 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@zhuzhuaicoding
zhuzhuaicoding / feedback.md
Created March 26, 2012 10:19
Feedback to "Async Javascript"

HI Trevor Burnham:

I'm a reader of your Async JavaScript book, I bought it on 23rd March and finished it on 26rd March, it is really a treasure to me, probably the best book about async programming in JavaScript I have ever read.

After finished this book, I found there are a few problems, as well as a set of my questions, exists, so I wrote this mail to you, expecting you could give a brief look.

Since I'm not a native English speaker, my English is really poor, so if there is any ambiguousness, please feedback to me so I could have a change to state it more clearly.

Fist of all, I would like to list 9 problems I found in this book, most of which are produced by the difference between our perspectives, so feel free is you don't think they are problems.

@zhuzhuaicoding
zhuzhuaicoding / LICENSE.txt
Created August 28, 2012 01:55 — forked from jed/LICENSE.txt
use anchor tags to parse URLs into components
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@zhuzhuaicoding
zhuzhuaicoding / 正则表达式lastIndex
Created September 20, 2012 13:29
check the change of lastIndex,and in greedy match what the result like.<http://jsfiddle.net/earlybird/RrZKH/2/>
//1.with greedy match and global flag
var re = /\s*/g;
for (var i = 0; i < 6; i++) {
console.log(re.exec(' as '));
console.log(re.lastIndex);//4,4,4,4,4,4
}
//2.without greedy match ,but global flag
var re1 = /\s/g;
for (var i = 0; i < 6; i++) {
@zhuzhuaicoding
zhuzhuaicoding / what the arguments really refer to
Created September 23, 2012 14:40
this gist aim at illustrating the arguments.
var what_the_arguments_refer_to = function(fn) {
return function() { // arguments -> this function
//debugger;
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [1].concat(args));
};
};
var console_log_closures = function(a, b, c) {
return console.log(a, b, c);
}
@zhuzhuaicoding
zhuzhuaicoding / getWH from a display-none element
Created September 30, 2012 02:20
a snippet for getW/H from a none displayed elemment by http://js8.in/781.html
function getCss(elem, css){
if (window.getComputedStyle) {
return window.getComputedStyle(elem, null)[css];
}else if (elem.currentStyle) {
return elem.currentStyle[css];
}else {
return elem.style[css];
}
}
function getWH(dom){
@zhuzhuaicoding
zhuzhuaicoding / GetCSS
Created September 30, 2012 02:21
getCSS style compatitable
function getCss(elem, css){
if (window.getComputedStyle) {
return window.getComputedStyle(elem, null)[css];
}else if (elem.currentStyle) {
return elem.currentStyle[css];
}else {
return elem.style[css];
}
}
@zhuzhuaicoding
zhuzhuaicoding / iframe-with-name
Created September 30, 2012 02:24
create an iframe with name for compatitable
var iframe;
try {
iframe = document.createElement('<iframe name="test">'); // for ie
} catch (ex) {
iframe = document.createElement('iframe');//for standard browser
}
iframe.name = 'test';