javascript - jquery中的原型鏈
問(wèn)題描述
var jQuery = function(global, factory) { return new jQuery.fn.init();}jQuery.fn = jQuery.prototype = { constructor: jQuery, init: function() {this.jquery = 3;return this; }, each: function() {console.log(’each’);return this; }}jQuery.fn.init.prototype = jQuery.fn;// init構(gòu)造函數(shù)jQuery().each().each()
上面是一段jQuery源碼,我的問(wèn)題是為什么代碼最后一行的第二個(gè)each函數(shù)還能夠執(zhí)行
問(wèn)題解答
回答1:原型中this指向的是實(shí)例對(duì)象,each里return this來(lái)返回這個(gè)對(duì)象,從而實(shí)現(xiàn)鏈?zhǔn)秸{(diào)用
回答2:兩個(gè)each跟一個(gè)each效果一樣,對(duì)象都是jQuery
回答3:因?yàn)槟鉹eturn的是this,別說(shuō)兩個(gè)了,10個(gè)也可以

鏈?zhǔn)骄幊?/p>
return this
相關(guān)文章:
1. 關(guān)于docker下的nginx壓力測(cè)試2. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?3. mac里的docker如何命令行開啟呢?4. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””5. nignx - docker內(nèi)nginx 80端口被占用6. docker容器呢SSH為什么連不通呢?7. dockerfile - 我用docker build的時(shí)候出現(xiàn)下邊問(wèn)題 麻煩幫我看一下8. docker-compose 為何找不到配置文件?9. docker start -a dockername 老是卡住,什么情況?10. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。

網(wǎng)公網(wǎng)安備