Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created November 17, 2010 23:55
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save paulirish/704386 to your computer and use it in GitHub Desktop.
Save paulirish/704386 to your computer and use it in GitHub Desktop.
10 or 11 or 12 things i learned from the jquery source
/*
.d dP"Yb dP"Yb 88""Yb .d .d dP"Yb 88""Yb .d oP"Yb. 888888 88 88 88 88b 88 dP""b8 .dP"Y8
.d88 dP Yb dP Yb 88__dP .d88 .d88 dP Yb 88__dP .d88 "' dP' 88 88 88 88 88Yb88 dP `" `Ybo."
88 Yb dP Yb dP 88"Yb 88 88 Yb dP 88"Yb 88 dP' 88 888888 88 88 Y88 Yb "88 o.`Y8b
88 YbodP YbodP 88 Yb 88 88 YbodP 88 Yb 88 .d8888 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
_ _____ _ _____ _ _
| | | __ \ | | |_ _| (_) | |
| |__ _ _ | |__) |__ _ _ _| | | | _ __ _ ___| |__
| '_ \| | | | | ___// _` | | | | | | | | '__| / __| '_ \
| |_) | |_| | | | | (_| | |_| | | _| |_| | | \__ \ | | |
|_.__/ \__, | |_| \__,_|\__,_|_| |_____|_| |_|___/_| |_|
__/ |
|___/
*/
____
_.' : `._
.-.'`. ; .'`.-.
__ / : ___\ ; /___ ; \ __
,'_ ""--.:__;".-.";: :".-.":__;.--"" _`,
:' `.t""--.. '<@.`;_ ',@>` ..--""j.' `;
`:-.._J '-.-'L__ `-- ' L_..-;'
"-.__ ; .-" "-. : __.-"
L ' /.------.\ ' J
"-. "--" .-"
__.l"-:_JL_;-";.__
.-j/'.; ;"""" / .'\"-.
.' /:`. "-.: .-" .'; `.
.-" / ; "-. "-..-" .-" : "-.
.+"-. : : "-.__.-" ;-._ \
; \ `.; ; : : "+. ;
: ; ; ; : ; : \:
; : ; : ;: ; :
: \ ; : ; : ; / ::
; ; : ; : ; : ;:
: : ; : ; : : ; : ;
;\ : ; : ; ; ; ;
: `."-; : ; : ; / ;
; -: ; : ; : .-" :
:\ \ : ; : \.-" :
;`. \ ; : ;.'_..-- / ;
: "-. "-: ; :/." .' :
\ \ : ;/ __ :
\ .-`.\ /t-"" ":-+. :
`. .-" `l __/ /`. : ; ; \ ;
\ .-" .-"-.-" .' .'j \ / ;/
\ / .-" /. .'.' ;_:' ;
:-""-.`./-.' / `.___.'
\ `t ._ / use the source, luke.
"-.t-._:'
// IFFE!!
// immediate function
(function loopsiloop() {
if (conditional){
doIt();
return;
}
setTimeout(loopsiloop, 500);
})();
// private, scope trav, munge and undefined
// async recursion
var jQuery = (function() {
bunchastuff();
// ...
return (window.jQuery = window.$ = jQuery);
})();
// pseudo module pattern
'methodname:';
// how to look at the source
<div data-omg="yay" data-awesum="true" data-hawtObj='{"best":"jQuery"}'></div>
$("div").data("omg") === "yay";
$("div").data("awesum") === true;
$("div").data("hawtObj").best === "jQuery";
if (data === "true"){
data = true;
} else if (data === "false"){
data = false;
} else if (data === "null"){
data = null;
} else if (!jQuery.isNaN(data)){
data = parseFloat(data);
} else if (rbrace.test(data)) {
data = jQuery.parseJSON(data);
} else {
data = data;
}
doc = context ? (context.ownerDocument || context : document);
const PEMDAS = 'Please Excuse My Dear Aunt Sally';
// https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence
// https://gist.github.com/527683/ef2abeb8e764d465ea430f440ebe4c534c8e3281
all = div.getElementsByTagName('i'); // live nodelist
document.querySelectorAll('i') // static nodelist
jQuery.cssHooks
// https://github.com/brandonaaron/jquery-cssHooks
// http://jsfiddle.net/paul/R4h4G/1/
// http://proj.jetless.org/AWESOME-TIME/
$(elem).css('box-shadow','10px 10px 30px #bada55')
jQuery.fn.plugin = function(){
doStuff();
return this;
};
var BAZ$ = jQuery.noConflict(true);
jQuery.props = {
"for": "htmlFor",
"class": "className",
readonly: "readOnly",
maxlength: "maxLength",
cellspacing: "cellSpacing",
rowspan: "rowSpan",
colspan: "colSpan",
tabindex: "tabIndex",
usemap: "useMap",
frameborder: "frameBorder"
};
<div aria-describedby="#foo">
jQuery.props.adb = 'aria-describedby';
jQuery('elem').attr('adb','#awesomething');
$(elem).fadeIn('default')
$(elem).animate('left','+=400px','normal');
// speeds:
// default longer for IE
jQuery.fx.speeds._default = ($.browser.msie && $.browser.version < 9) ?
800 : 400;
bindReady()
// http://javascript.nwbox.com/IEContentLoaded/
// duck punch to pass in window and doc
// http://gist.github.com/315916
$.getJSON(), $.getScript()
// convenience methods
$.getScript() -> getScript()
$('selector#performance:matters')
// Sizzle.filters.POS vs .eq(0)
$('p:lt(5)') // 1.2ms
$('p').slice(0,4); // .6ms
// '#id' vs '#id tag.thing'
$(':password')
$.parseJSON(jsonstr);
condition && ternary ? 'crazy' : 'cool';
new Function
$.unique(arr)
// http://api.jquery.com/jQuery.unique/
// http://paulirish.com/2010/duck/-punching-with-jquery/
$(elem).height(), $(elem).innerHeight(), $(elem).outerHeight();
jQuery.support = {};
'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
@jitter
Copy link

jitter commented Nov 18, 2010

hmm closing brace on https://gist.github.com/704386#LC200 seems wrong

@paulirish
Copy link
Author

@jitter, agreed. This was a dump of my video session.. There are probably a few syntax issues. :)
I'll rerecord the video probably so it can be seen in context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment