The question about zepto.Z.prototype = $.fn’ in zepto source code

  javascript, jquery

During the recent reading of zepto (Version v1.1.6) source code, there was one thing that I didn’t want to understand. First see line 155:

zepto.Z = function(dom, selector) {
 dom = dom || []
 dom.__proto__ = $.fn
 dom.selector = selector || ''
 return dom

among themdom.__proto__ = $.fnYes, it isdom arraypoint to$.fnThat makes thisdom arrayAble to use$.fnThis is understandable and no problem. But in line 874, there is a code like this:

zepto.Z.prototype = $.fn

My understanding is that this sentence makeszepto.ZInherit from$.fn, but the abovedom.__proto__ = $.fnIt has been realized that “thisdom arrayAble to use$.fnAll methods “function, why add this sentence?

Later, I wrote a demo by reference. The code is as follows:

var Otpez = (function () {
 var $,
 otpez = {}
 otpez.Z = function (dom, selector) {
 dom = dom || []
 dom.__proto__ = $.fn
 dom.selector = selector || ''
 return dom
 otpez.init = function (selector, context) {
 var dom
 return otpez.Z(dom, selector)
 $ = function(selector, context) {
 return new otpez.init(selector, context)
 $.fn = {
 sayHello: function () {
 console.log('Hello otpez!'  )
 return this
 $.otpez = otpez
 return $

There is nothing in itotpez.Z.prototype = $.fnTo be able to output correctlyHello otpez!

So I hope I can get the answer from the great god, zepto source codezepto.Z.prototype = $.fnWhat exactly is it used for?
Thank you!

var F = function(){}
 var f = new F()
 f.__proto__ === F.prototype   //true

Do you understand this, an instance of a class__proto__With this classprototypeConsistent.

Zepto is also based on this, dom instance__proto__With zepto.ZprototypeAccording to the agreement, it is equivalent to saying that the final return of $ is actually an instance of zepto.Z

Although zepto.Z was defined earlier, it was not called before.zepto.Z.prototype = $.fnIt has already been carried out.

$('body').__proto__ === $.zepto.Z.prototype     //true
 Otpez().__proto__ === Otpez.otpez.Z.prototype   //false