public
Last active

10 things i learned from the jquery source

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
/*
 
 
 
 
 
.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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.