第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

價值,原型和特性的差異

價值,原型和特性的差異

墨色風(fēng)雨 2019-09-26 14:59:31
價值,原型和特性的差異好!首先,這個問題來自于一個在jQuery宇宙中挖得太深(很可能迷路)的人。在我的研究中,我發(fā)現(xiàn)了jquery的主要模式是這樣的(如果需要更正的話):(function (window, undefined) {    jQuery = function (arg) {       // The jQuery object is actually just the init constructor 'enhanced'       return new jQuery.fn.init(arg);    },    jQuery.fn = jQuery.prototype = {       constructor: jQuery,       init: function (selector, context, rootjQuery) {          // get the selected DOM el.          // and returns an array       },       method: function () {          doSomeThing();          return this;       },       method2: function () {          doSomeThing();          return this;,          method3: function () {             doSomeThing();             return this;          };          jQuery.fn.init.prototype = jQuery.fn;          jQuery.extend = jQuery.fn.extend = function () {             //defines the extend method           };          // extends the jQuery function and adds some static methods           jQuery.extend({             method: function () {}          })       })當(dāng)$啟動時,jQuery.prototype.init啟動并返回一個元素數(shù)組。但我不明白它是如何增加了jQuery的方法類似.css或.hide等。到這個數(shù)組。我得到了靜態(tài)方法。但是用所有這些方法都無法獲得返回值和元素數(shù)組的方式。
查看完整描述

2 回答

?
HUH函數(shù)

TA貢獻1836條經(jīng)驗 獲得超4個贊

我也不喜歡這種模式。他們有一個init函數(shù),它是所有jQuery實例的構(gòu)造jQuery函數(shù)-該函數(shù)本身只是對象創(chuàng)建過程的包裝器new

function jQuery(…) { return new init(…); }

然后,他們將這些實例的方法添加到init.prototype對象中。該對象作為接口公開jQuery.fn。另外,他們將prototypejQuery函數(shù)的屬性設(shè)置為該對象-對于不使用該fn屬性的用戶。現(xiàn)在你有

jQuery.prototype = jQuery.fn = […]init.prototype

但是他們也做兩件事:

  • 覆蓋constructor原型對象的屬性,將其設(shè)置為jQuery函數(shù)

  • 公開init功能jQuery.fn-自己的原型。這可能允許擴展$ .fn.init函數(shù),但非常令人困惑

我認(rèn)為他們需要/想要做所有這些事情以防萬一,但是他們的代碼是一團糟-從該對象文字開始,然后分配初始化原型。


查看完整回答
反對 回復(fù) 2019-09-26
?
紅糖糍粑

TA貢獻1815條經(jīng)驗 獲得超6個贊

如果將API視為方法的外部集合,而將jQuery函數(shù)視為包裝器,則更容易消化。

它的基本構(gòu)造如下:

function a() { return new b();}a.prototype.method = function() { return this; }function b() {}b.prototype = a.prototype;

除了ajQuerybjQuery.prototype.init

我確定Resig有將他的api構(gòu)造函數(shù)放在init原型中的原因,但是我看不到它們。除了Bergi提到的以外,還有其他一些奇怪之處:

1)圖案需要從參考副本jQuery.fn.init.prototypejQuery.prototype,至極允許怪異無端環(huán):

var $body = new $.fn.init.prototype.init.prototype.init.prototype.init('body');

2)每個jQuery集合實際上是的一個實例jQuery.fn.init,但是由于它們引用相同的原型對象,因此欺騙我們“認(rèn)為”該集合是的實例jQuery。您可以執(zhí)行以下相同的魔術(shù):

function a(){}function b(){}a.prototype = b.prototype;console.log( new b instanceof a); // trueconsole.log( new a instanceof b); // true

旁注:我個人使用了以下構(gòu)造函數(shù)模式,結(jié)果相似但沒有怪異:

var a = function(arg) {
    if (!(this instanceof a)) {
        return new a(arg);
    }};a.prototype.method = function(){ return this; };


查看完整回答
反對 回復(fù) 2019-09-26
  • 2 回答
  • 0 關(guān)注
  • 542 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號