Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created June 14, 2010 21:27
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paulirish/438326 to your computer and use it in GitHub Desktop.
Save paulirish/438326 to your computer and use it in GitHub Desktop.
10 things i learned from the jquery source
/*
.d dP"Yb 888888 88 88 88 88b 88 dP""b8 .dP"Y8
.d88 dP Yb 88 88 88 88 88Yb88 dP `" `Ybo."
88 Yb dP 88 888888 88 88 Y88 Yb "88 o.`Y8b
88 YbodP 88 88 88 88 88 Y8 YboodP 8bodP'
88 88 888888 db 88""Yb 88b 88 888888 8888b. 888888 88""Yb dP"Yb 8b d8
88 88 88__ dPYb 88__dP 88Yb88 88__ 8I Yb 88__ 88__dP dP Yb 88b d88
88 88 .o 88"" dP__Yb 88"Yb 88 Y88 88"" 8I dY 88"" 88"Yb Yb dP 88YbdP88
88 88ood8 888888 dP""""Yb 88 Yb 88 Y8 888888 8888Y" 88 88 Yb YbodP 88 YY 88
888888 88 88 888888 88888 dP"Yb 88 88 888888 88""Yb Yb dP .dP"Y8 dP"Yb 88 88 88""Yb dP""b8 888888
88 88 88 88__ 88 dP Yb 88 88 88__ 88__dP YbdP `Ybo." dP Yb 88 88 88__dP dP `" 88__
88 888888 88"" o. 88 Yb b dP Y8 8P 88"" 88"Yb 8P o.`Y8b Yb dP Y8 8P 88"Yb Yb 88""
88 88 88 888888 "bodP' `"YoYo `YbodP' 888888 88 Yb dP 8bodP' YbodP `YbodP' 88 Yb YboodP 888888
_ _____ _ _____ _ _
| | | __ \ | | |_ _| (_) | |
| |__ _ _ | |__) |__ _ _ _| | | | _ __ _ ___| |__
| '_ \| | | | | ___// _` | | | | | | | | '__| / __| '_ \
| |_) | |_| | | | | (_| | |_| | | _| |_| | | \__ \ | | |
|_.__/ \__, | |_| \__,_|\__,_|_| |_____|_| |_|___/_| |_|
__/ |
|___/
*/
/*
888 888 888 888
888 888 888 888
888 888 888 888
88888b. 888 8888b. .d8888b 888 888 88888b. .d88b. 888 888
888 "88b 888 "88b d88P" 888 .88P 888 "88b d88""88b `Y8bd8P'
888 888 888 .d888888 888 888888K 888 888 888 888 X88K
888 d88P 888 888 888 Y88b. 888 "88b 888 d88P Y88..88P .d8""8b.
88888P" 888 "Y888888 "Y8888P 888 888 88888P" "Y88P" 888 888
*/
((((function () {
})))()
// http://twitter.com/paul_irish/status/9686471408
// scope, munge and undefined
// async recursion
(function (){
arguments.callee();
}())
//setInterval(function(){ ... },1000)
'methodname:';
// how to look at the source
jQuery.noConflict();
jQuery.props
jQuery.props = {
"for": "htmlFor",
"class": "className",
readonly: "readOnly",
maxlength: "maxLength",
cellspacing: "cellSpacing",
rowspan: "rowSpan",
colspan: "colSpan",
tabindex: "tabIndex",
usemap: "useMap",
frameborder: "frameBorder"
};
$.extend(jQuery.props,{a: 'aria-enabled-by'};
$(elem).attr('a','lsdjflsdj')
$(elem).fadeIn('mediusdlfkjsdflkjs')
// speeds:
// default longer for IE
jQuery.fx.speeds._default = ($.browser.msie && $.browser.version >= 7) ?
800 : 400;
$(document).ready(function(){
});
bindReady()
// http://javascript.nwbox.com/IEContentLoaded/
$.getJSON(), $.getScript()
// convenience methods
$.getScript() -> getScript()
function getScript(url,callback){
var head = document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
script.src = url;
var done = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
done = true;
callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
}
};
head.insertBefore(script, head.firstChild);
}
getScript('http://www.cornify.com/js/cornify.js',function(){
var times = 38;
while(--times) cornify_add();
})
show()
$(elem).show()
//vs the Prototype show technique
$('selector#performance:matters')
$('p:lt()') // 1.2ms
$('p').slice(0,4); // .6ms
$('#myelemenid').bind()
// Sizzle.filters.POS vs .eq(0)
// '#id' vs '#id tag.thing'
$('#mypassword').fadeOut().fadeIn();
var $result = $('p.result');
$result.load()
$.parseJSON(jsonstr);
condition && ternary ? 'crazy' : 'cool';
new Function
var mytimeout = setTimeout(fn,20000);
clearTimeout(mytimeout);
fn();
var mytimeout = setTimeout(fn,20000);
// Try to use the native JSON parser first
return window.JSON && window.JSON.parse ?
window.JSON.parse(data) :
( new Function("return " + data) )();
return eval('('+ data+')');
//juqyer
var myjQ = jQuery.noConflict(true);
$.unique(arr)
// http://api.jquery.com/jQuery.unique/
// http://paulirish.com/2010/duck/-punching-with-jquery/
$(elem).delay(2000).load('mypage.html #thing');
$(elem).height(), $(elem).innerHeight(), $(elem).outerHeight()
jQuery.support = {};
jQuery.support.boxModel // true
'git clone git://github.com/jquery/jquery.git';
// how the source is put together, build system
// dependencies by source order. git clones.
/*
888 d8b 888 888 d88P d8b
888 Y8P 888 888 d88P Y8P
888 888 888 d88P
88888b. 888 888888 888 888 888 d88P 8888 .d88888 .d8888b .d88b. 888 888 888d888 .d8888b .d88b.
888 "88b 888 888 888 888 888 d88P "888 d88" 888 88K d88""88b 888 888 888P" d88P" d8P Y8b
888 888 888 888 888 888 888 d88P 888 888 888 "Y8888b. 888 888 888 888 888 888 88888888
888 d88P 888 Y88b. d8b 888 Y88b 888 d88P 888 Y88b 888 X88 Y88..88P Y88b 888 888 Y88b. Y8b.
88888P" 888 "Y888 Y8P 888 "Y88888 d88P 888 "Y88888 88888P' "Y88P" "Y88888 888 "Y8888P "Y8888
888 888 888
Y8b d88P d88P 888
"Y88P" 888P" 888
http://bit.ly/jqsource
*/
888 888 888 888
888 888 888 888
888 888 888 888
888888 88888b. 8888b. 88888b. 888 888 .d8888b 888
888 888 "88b "88b 888 "88b 888 .88P 88K 888
888 888 888 .d888888 888 888 888888K "Y8888b. Y8P
Y88b. 888 888 888 888 888 888 888 "88b X88 "
"Y888 888 888 "Y888888 888 888 888 888 88888P' 888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment