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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Jquery源碼學(xué)習(xí)(第三天)

標(biāo)簽:
JQuery

jquery变量和函数的学习(21行-94行)--更新①:

一、 第14行代码到8829行结尾函数闭合,代码片段:

// 14行
(function(window,undefined){
.....
})(window);

此处是一个匿名函数自执行
① “函数表达式”与“函数声明”区别
注意:(function(window,undefined){});代表"函数表达式"(以分号结尾,它是一个执行语句,例如

var x = function (a, b) {return a * b};
var z = x(4, 3);

此处的function (a, b) {return a b};代表函数表达式,以上函数实际上是一个 匿名函数 (函数没有名称),函数存储在变量x中,不需要函数名称,通常通过变量名来调用*,如:x(4, 3);
而该表达式内部的function(window,undefined){}代表“函数声明”(结尾没有分号,它不是一个执行语句,函数声明后不会立即执行,我们需要的时候调用。
② 匿名函数自执行
1.如果表达式后面紧跟 () ,则会自动调用。
2.不能自调用声明的函数,通过添加括号,来说明它是一个函数表达式:
③ 匿名函数自执行参数说明
通常,全局变量被作为一个参数传递给立即执行参数
图片描述

图①表示全局变量(window对象),图②表示执行参数
④ 传参作用级执行参数作用

  1. window

1.通过外部传来的全局window对象,让匿名函数内部能更快的查找到全局window对象,因为js中查找变量是从"局部"到"全局"的范围查找。
2.有利于代码的压缩,压缩时可以改变局部变量的名称,如果不传全局window对象,匿名函数内部使用全局window对象压缩时名称不能改变。

  1. undefined

Undefined是window下的一个属性,但是因为在有些浏览器下undefined的是可以被修改的。例如在IE8下面:

var undefined = 10;
alert(undefined); // 10

因此传入undefined的作用就是为了防止外部的对undefined进行修改,这样jQuery内部如果访问undefined的,首先访问到的是传入的undefined参数,而不会访问外部的undefined,所以即使外部对undefined进行了修改,也没有影响。
二、第21行代码起涉及的变量,代码片段

var
// A central reference to the root jQuery(document)
rootjQuery,

// The deferred used on DOM ready
readyList,

// Support: IE9
// For `typeof xmlNode.method` instead of `xmlNode.method !== undefined`
core_strundefined = typeof undefined,

// Use the correct document accordingly with window argument (sandbox)
location = window.location,
document = window.document,
docElem = document.documentElement,

// Map over jQuery in case of overwrite
_jQuery = window.jQuery,

// Map over the $ in case of overwrite
_$ = window.$,

// [[Class]] -> type pairs
class2type = {},

// List of deleted data cache ids, so we can reuse them
core_deletedIds = [],

core_version = "2.0.3",

// Save a reference to some core methods
core_concat = core_deletedIds.concat,
core_push = core_deletedIds.push,
core_slice = core_deletedIds.slice,
core_indexOf = core_deletedIds.indexOf,
core_toString = class2type.toString,
core_hasOwn = class2type.hasOwnProperty,
core_trim = core_version.trim,
  • rootjQuery
rootjQuery = jQuery(document);

代码866行,通过jQuery选择document元素赋给rootjQuery,rootjQuery就是document。这样做有利于压缩以及代码的易读性(通常我们习惯将一个值其赋给一个变量)。

  • readyList

与DOM 加载有关

  • core_strundefined = typeof undefined

兼容处理,typeof 操作符来检测变量的数据类型,此处检验String类型,此处使用typeof undefined而不是用'undefined'作为判断,是为了解决老版本浏览器无法使用'undefined'判断XML中的String类型。

  • location 、document 、docElem

保存相应的js对象,方便jquery内部操作,方便压缩。

  • _jQuery、_$

为了防止外部与内部定义的jQuery和$变量冲突,这两个变量用来保存外部传来的jQuery和$变量。

  • class2type

用于类型判断,它的数组中会以json格式保存多种类型值,如

class2type  = {'[Object String]' : 'string' , '[Object Array]' : 'array' ,...}
  • core_deletedIds

老版本的删除缓存数据的变量,2.0.3版本后不使用此变量。

  • core_concat 、...、core_trim

变量的存储

點(diǎn)擊查看更多內(nèi)容
2人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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

舉報(bào)

0/150
提交
取消