yaotti's diary

Software is Eating the World

jQueryコードリーディング

jQuery1.4.2のコードリーディング.

最初はkmdsbngさんの説明

jQueryの基本的な仕組みと使い方

一貫性のあるエレガントな設計,pluginが豊富
prototype.jsとの比較

  • prototype.js
    • ロジック中心
    • クラスの概念
    • 既存オブジェクトを拡張している
  • jQuery
    • DOM中心
    • jQueryオブジェクト($)を拡張して機能をつける

jQueryオブジェクトの作りかた
$("

", {"class": "test"})とすると
jQueryオブジェクトが返ってくる

jQuery code reading

function hoge(a, b){};
で,hoge(a)と呼ぶとbにはundefinedが入る("undefined"が上書きされる可能性があるので,undefined値を得るためにこうする)



Array.prototype.slice.call(arguments)
callなんてあるのかー

jQuery.fn.someMethodはjQueryオブジェクト($('a')とかで返ってくるやつ)に紐付くメソッド, jQuery.someMethodは$に紐付くメソッド


jQuery.extend: オブジェクトをmergeする
jQuery.extend() – jQuery API

head.insertBefore( script, head.firstChild );
head.removeChild( script );

jsをグローバルコンテキストで実行するために, scriptタグで入れてすぐ消す