国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

Prototype學習工具函數學習($A方法)_prototype

來源:懂視網 責編:小采 時間:2020-11-27 20:43:27
文檔

Prototype學習工具函數學習($A方法)_prototype

Prototype學習工具函數學習($A方法)_prototype:$A方法: Accepts an array-like collection (anything with numeric indices) and returns its equivalent as an actual Array object. This method is a convenience alias of Array.from, but
推薦度:
導讀Prototype學習工具函數學習($A方法)_prototype:$A方法: Accepts an array-like collection (anything with numeric indices) and returns its equivalent as an actual Array object. This method is a convenience alias of Array.from, but

$A方法:
Accepts an array-like collection (anything with numeric indices) and returns its equivalent as an actual Array object. This method is a convenience alias of Array.from, but is the preferred way of casting to an Array.
代碼如下:
function $A(iterable) {
if (!iterable) return [];
if ('toArray' in Object(iterable)) return iterable.toArray();
var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length];
return results;
}

如果傳進來的參數為null, undefined and false 則直接返回空數組
如果傳進來的參數對象里有toArray方法,這直接調用參數的toArray方法,因為有許多Prototype對象里面已經定義好了toArray方法,所以可以直接調用toArray方法
例如:
代碼如下:
var array={
toArray : function(){
return [1,2,3];
}
}
//1,2,3
alert($A(array));

接下來根據參數的length建立新數組,然后逐個把參數中的元素復制到新數組中去,最后返回新數組對象
下面給出prototype幫助文檔的一段說明和例子也許更能說明這個函數的作用:
代碼如下:
/*The well-known DOM method document.getElementsByTagName() doesn't return an Array, but a NodeList object that implements the basic array "interface." Internet Explorer does not allow us to extend Enumerable onto NodeList.prototype, so instead we cast the returned NodeList to an Array:*/
var paras = $A(document.getElementsByTagName('p'));
paras.each(Element.hide);
$(paras.last()).show();

還有一點:
Array.from = $A;
數組對象的from靜態方法和$A是一個方法

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

Prototype學習工具函數學習($A方法)_prototype

Prototype學習工具函數學習($A方法)_prototype:$A方法: Accepts an array-like collection (anything with numeric indices) and returns its equivalent as an actual Array object. This method is a convenience alias of Array.from, but
推薦度:
標簽: pro 函數 方法)
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 草逼视频免费看 | 日本一区二区三区免费观看 | 欧美视频亚洲视频 | 日韩美在线 | 亚洲欧美日韩色图 | 欧美日韩免费电影 | 国产一二三区在线观看 | 中文字幕第一页亚洲 | 亚洲精品午夜国产va久久成人 | 欧美另类第一页 | 亚洲一区二区成人 | 国产视频一区二区在线播放 | 国产欧美日韩三级 | 国产一级片免费观看 | 免费在线观看的视频 | 精品123区 | 欧美成人精品高清在线播放 | 国产一区二区三区视频在线观看 | 欧美色第一页 | 国产91成人精品亚洲精品 | 国产一二三区在线 | 国产精品美女流白浆视频 | 国产网站在线免费观看 | 国产高清一级在线观看 | 日韩欧美区| 欧美性xxxxxx爱 | 亚洲国产精品嫩草影院久久 | 久久综合精品国产一区二区三区 | 自拍偷拍日韩 | h片免费在线观看 | 国产欧美久久久精品影院 | 就爱啪啪网站 | 日本一区二区三区免费高清在线 | 欧美国产第一页 | 久久婷婷色一区二区三区 | 欧美亚洲国产一区二区 | 日韩欧美在线看 | 日韩亚射| 亚洲成a人一区二区三区 | 日韩亚洲欧洲在线com91tv | 日韩免费在线观看视频 |