在jQuery中,
fn属性只是该属性的别名
prototype。
jQuery标识符(或
$)只是一个 构造函数 ,使用该标识符创建的所有实例都从构造函数的原型继承。
一个简单的构造函数:
function Test() { this.a = 'a';}Test.prototype.b = 'b';var test = new Test(); test.a; // "a", own propertytest.b; // "b", inherited property一个类似于jQuery体系结构的简单结构:
(function() { var foo = function(arg) { // core constructor // ensure to use the `new` operator if (!(this instanceof foo)) return new foo(arg); // store an argument for this example this.myArg = arg; //.. }; // create `fn` alias to `prototype` property foo.fn = foo.prototype = { init: function () {} //... }; // expose the library window.foo = foo;})();// Extension:foo.fn.myPlugin = function () { alert(this.myArg); return this; // return `this` for chainability};foo("bar").myPlugin(); // alerts "bar"


