## 新舊對比
在準備課程的這個時間 https://github.com/madrobby/zepto/blob/master/src/zepto.js#files 其中的代碼中,`zepto.Z`是這樣實現的:
```js
function Z(dom, selector) {
var i, len = dom ? dom.length : 0
for (i = 0; i < len; i++) this[i] = dom[i]
this.length = len
this.selector = selector || ''
}
// `$.zepto.Z` swaps out the prototype of the given `dom` array
// of nodes with `$.fn` and thus supplying all the Zepto functions
// to the array. This method can be overridden in plugins.
zepto.Z = function(dom, selector) {
return new Z(dom, selector)
}
$.fn = {
// ...很多屬性...
}
zepto.Z.prototype = Z.prototype = $.fn
```
再把之前的拿出來對比一下
```js
// `$.zepto.Z` swaps out the prototype of the given `dom` array
// of nodes with `$.fn` and thus supplying all the Zepto functions
// to the array. Note that `__proto__` is not supported on Internet
// Explorer. This method can be overriden in plugins.
zepto.Z = function(dom, selector) {
dom = dom || []
dom.__proto__ = $.fn
dom.selector = selector || ''
return dom
}
$.fn = {
// ...很多屬性...
}
```
<br>
## 兩者的異同
第二種實現方式我們已經講完了,最終它返回的一個數組,并且強制將`__proto__`修改為`$.fn`這個對象。這個修改發生在對象上,修改的隱式原型。

而第一種實現方式,是直接將構造函數的原型修改了,即 `Z.prototype = $.fn`,經過這樣一改,構造函數再`new`出來的對象的隱式原型`__proto__`自然就指向了`$.fn`。

另外,第一種方式返回的是一個`對象數組`,而第二種返回的是一個數組。何謂對象數組?——即可以模擬進行數組操作的對象。
```js
var objArray = {
0: 'abc',
1: 'bcd',
2: 'cde',
length: 3
};
console.log( objArray[1] )
console.log( objArray.length )
```
那為何不用數組,而用對象數組?——對象本質上更加靈活、直觀,例如
```js
objArray.selector = '';
```