作者annypeter (黑貓)
看板Ajax
標題[問題] 一段看不懂的javascript
時間Wed Aug 8 12:42:52 2007
這是從cookie的網頁中截取的一段,
小女子我看不太懂是什麼意思Q_Q
prototype.splice怎麼用?
整段下來又是做什麼用的呢?是刪除嗎?
(↑因為我在其它地方找不到刪除的功能...QQ)
if (!Array.prototype.splice) {
function array_splice(ind,cnt) {
if (arguments.length == 0) return ind;
if (typeof ind != "number") ind = 0;
if (ind < 0) ind = Math.max(0,this.length + ind);
if (ind > this.length) {
if (arguments.length > 2) ind = this.length;
else return [];
}
if (arguments.length < 2) cnt = this.length-ind;
cnt = (typeof cnt == "number") ? Math.max(0,cnt) : 0;
removeArray = this.slice(ind,ind+cnt);
endArray = this.slice(ind+cnt);
this.length = ind;
for (var i = 2; i < arguments.length; i++) {
this[this.length] = arguments[i];
}
for(var i = 0; i < endArray.length; i++) {
this[this.length] = endArray[i];
}
return removeArray;
}
Array.prototype.splice = array_splice;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.230.174.215
1F:推 braveht:檢查Array有沒有支援splice這個方法 沒有的話自己寫一個 08/08 13:01
2F:推 annypeter:我查過網路,應該是有,但是沒寫怎麼用 08/08 13:27