作者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