兼容低版本IE的JScript5.5实现

时间:2021-05-25

作者Blog:ponent(str) { function throwerror() { @if (@_jscript_version > 6) != 2) { return throwerror(); } } var out, i, j, len; var c, c2, c3, c4, s; out = []; len = str.length; i = j = 0; while(i > 4) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: { // 0xxxxxxx out[j++] = String.fromCharCode(c); break; } case 12: case 13: { // 110x xxxx 10xx xxxx if ((c2 = checkutf8()) == null) return null; out[j++] = String.fromCharCode(((c & 0x1F) << 6) | (c2 & 0x3F)); break; } case 14: { // 1110 xxxx 10xx xxxx 10xx xxxx if ((c2 = checkutf8()) == null) return null; if ((c3 = checkutf8()) == null) return null; out[j++] = String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0)); break; } default: { switch (c & 0xf) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: { // 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx if ((c2 = checkutf8()) == null) return null; if ((c3 = checkutf8()) == null) return null; if ((c4 = checkutf8()) == null) return null; s = ((c & 0x07) << 18) | ((c2 & 0x3f) << 12) | ((c3 & 0x3f) << 6) | (c4 & 0x3f) - 0x10000; if (0 <= s && s >> 10) & 0x03ff) | 0xd800, (s & 0x03ff) | 0xdc00); } else { return throwerror(); } break; } default: { return throwerror(); } } } } } return out.join(''); } Array.prototype.push = function () { var curlen = this.length; for (var i = 0; i < arguments.length; i++) { this[curlen + i] = arguments[i]; } return this.length; } Array.prototype.pop = function () { var returnValue = this[this.length - 1]; this.length--; return returnValue; } Array.prototype.shift = function () { var returnValue = this[0]; for (var i = 1; i = 0 ; i--) { this[i + arglen] = this[i] ; } for (var i = 0; i < arglen; i++) { this[i] = arguments[i]; } //return this.length; // return this value is Gecko/Opera implementation. but IE don't return anything. } Array.prototype.splice = function () { var start = arguments[0]; var deleteCount = arguments[1]; var len = arguments.length - 2; var returnValue = this.slice(start); for (var i = 0; i < len; i++) { this[start + i] = arguments[i + 2]; } for (var i = 0; i < returnValue.length - deleteCount; i++) { this[start + len + i] = returnValue[deleteCount + i]; } this.length = start + len + returnValue.length - deleteCount; returnValue.length = deleteCount; return returnValue; } Function.prototype.apply = function (o, p) { var ps = []; if (typeof(o) == "undefined") { var __$$apply$$__ = this; return eval('__$$apply$$__(' + ps.join(', ') + ');'); } if (p) { if (typeof(p[0]) == "undefined") { @if (@_jscript_version < 5) return null; @else var e = new Error(-2146823260, "Array or arguments object expected"); e.name = "TypeError"; e.message = e.description; throw(e); @end } for (var i = 0; i 1) { for (var i = 1; i < arguments.length; i++) { ps[i - 1] = 'arguments[' + i + ']'; } } if ((typeof(o) == "object") || (typeof(o) == "function")) { o.__$$call$$__ = this; var returnValue = eval('o.__$$call$$__(' + ps.join(', ') + ');'); o.__$$call$$__ = null; return returnValue; } else { this.__$$call$$__ = this; var returnValue = eval('this.__$$call$$__(' + ps.join(', ') + ');'); this.__$$call$$__ = null; return returnValue; } } @end @*/ [Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
如果你想测试低版本的 IE 浏览器上的效果,又没有安装低版本的 IE 浏览器,可以使用这个包:ie_all.zip。这里面都是不需要安装的 IE,直接释放压缩包到一个目录下,就可以运行了。如果你是 win9x 系统,可以到 这里下载 win9x 版的 standalone IE。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章