``````const arr = [1, 2, 3, 4, 5, 6]

``````Array.prototype.getReader = function () {
//复制原数组
return {
//如果有参数，判断参数
if (num) {
try {
if (typeof num == "string") {
throw Error();
} else if (!/(^[1-9]\d*\$)/.test(num)) {
//正则判断正整数 /^[1-9]\d*\$/
throw Error();
} else {
}
} catch (e) {
return "Error";
}
} else {
}
},
};
};``````

``````Array.prototype.getReader = function () {
//拿到原数组
let that = this;
let count = 0;
return {
//如果有参数，判断参数
if (num) {
try {
if (typeof num == "string") {
throw Error();
} else if (!/(^[1-9]\d*\$)/.test(num)) {
//正则判断正整数 /^[1-9]\d*\$/
throw Error();
} else {
let res = that.slice(count, count + num);
count = count + num;
return res;
}
} catch (e) {
return "Error";
}
} else {
//如果没有参数，默认为1
if (that.length) {
let res = that.slice(count, count + 1);
count = count + 1;
return res;
} else {
return [];
}
}
},
};
};``````
``````//实例
const arr = [1, 2, 3, 4, 5, 6];
————————

``````const arr = [1, 2, 3, 4, 5, 6]

``````Array.prototype.getReader = function () {
//复制原数组
return {
//如果有参数，判断参数
if (num) {
try {
if (typeof num == "string") {
throw Error();
} else if (!/(^[1-9]\d*\$)/.test(num)) {
//正则判断正整数 /^[1-9]\d*\$/
throw Error();
} else {
}
} catch (e) {
return "Error";
}
} else {
}
},
};
};``````

``````Array.prototype.getReader = function () {
//拿到原数组
let that = this;
let count = 0;
return {
//如果有参数，判断参数
if (num) {
try {
if (typeof num == "string") {
throw Error();
} else if (!/(^[1-9]\d*\$)/.test(num)) {
//正则判断正整数 /^[1-9]\d*\$/
throw Error();
} else {
let res = that.slice(count, count + num);
count = count + num;
return res;
}
} catch (e) {
return "Error";
}
} else {
//如果没有参数，默认为1
if (that.length) {
let res = that.slice(count, count + 1);
count = count + 1;
return res;
} else {
return [];
}
}
},
};
};``````
``````//实例
const arr = [1, 2, 3, 4, 5, 6];