From 879cff57fe04fe560ad64817cab0048a6e6e365b Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 22 Jan 2018 16:38:32 +0800 Subject: [PATCH] =?UTF-8?q?IE8=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/bundle.js | 82 +++++++++++++++++++++++++++- dist/core.js | 82 +++++++++++++++++++++++++++- dist/fineui.js | 112 +++++++++++++++++++++++++++++++++++++-- dist/polyfill.js | 30 ++++++++++- src/core/proto/date.js | 82 +++++++++++++++++++++++++++- src/polyfill/function.js | 29 ++++++++++ 6 files changed, 407 insertions(+), 10 deletions(-) create mode 100644 src/polyfill/function.js diff --git a/dist/bundle.js b/dist/bundle.js index ba5fe11d8..8fe8fb5b2 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -21315,7 +21315,46 @@ Date.parseDateTime = function (str, fmt) { }; Date.getDate = function () { - var dt = new (Function.prototype.bind.apply(Date, BI.concat([null], [].slice.apply(arguments))))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { var localTime = dt.getTime(); var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 @@ -21327,7 +21366,46 @@ Date.getDate = function () { }; Date.getTime = function () { - var dt = Function.prototype.bind.apply(Date.getDate, BI.concat([null], [].slice.apply(arguments)))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone)) { return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; } diff --git a/dist/core.js b/dist/core.js index ac0acaa92..6d70f5770 100644 --- a/dist/core.js +++ b/dist/core.js @@ -21315,7 +21315,46 @@ Date.parseDateTime = function (str, fmt) { }; Date.getDate = function () { - var dt = new (Function.prototype.bind.apply(Date, BI.concat([null], [].slice.apply(arguments))))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { var localTime = dt.getTime(); var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 @@ -21327,7 +21366,46 @@ Date.getDate = function () { }; Date.getTime = function () { - var dt = Function.prototype.bind.apply(Date.getDate, BI.concat([null], [].slice.apply(arguments)))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone)) { return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; } diff --git a/dist/fineui.js b/dist/fineui.js index 714b3f902..54e6bed30 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -106,7 +106,35 @@ window.console = window.console || (function () { }; return c; })(); -/* +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (typeof this !== 'function') { + // closest thing possible to the ECMAScript 5 + // internal IsCallable function + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof fNOP + ? this + : oThis, + // 获取调用时(fBound)的传参.bind 返回的函数入参往往是这么传递的 + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + // 维护原型关系 + if (this.prototype) { + // Function.prototype doesn't have a prototype property + fNOP.prototype = this.prototype; + } + fBound.prototype = new fNOP(); + + return fBound; + }; +}/* * 前端缓存 */ window.localStorage || (window.localStorage = { @@ -21488,7 +21516,46 @@ Date.parseDateTime = function (str, fmt) { }; Date.getDate = function () { - var dt = new (Function.prototype.bind.apply(Date, BI.concat([null], [].slice.apply(arguments))))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { var localTime = dt.getTime(); var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 @@ -21500,7 +21567,46 @@ Date.getDate = function () { }; Date.getTime = function () { - var dt = Function.prototype.bind.apply(Date.getDate, BI.concat([null], [].slice.apply(arguments)))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone)) { return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; } diff --git a/dist/polyfill.js b/dist/polyfill.js index 0b8245d52..052cfb574 100644 --- a/dist/polyfill.js +++ b/dist/polyfill.js @@ -106,7 +106,35 @@ window.console = window.console || (function () { }; return c; })(); -/* +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (typeof this !== 'function') { + // closest thing possible to the ECMAScript 5 + // internal IsCallable function + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof fNOP + ? this + : oThis, + // 获取调用时(fBound)的传参.bind 返回的函数入参往往是这么传递的 + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + // 维护原型关系 + if (this.prototype) { + // Function.prototype doesn't have a prototype property + fNOP.prototype = this.prototype; + } + fBound.prototype = new fNOP(); + + return fBound; + }; +}/* * 前端缓存 */ window.localStorage || (window.localStorage = { diff --git a/src/core/proto/date.js b/src/core/proto/date.js index 6f3a26d35..a2c3e4095 100644 --- a/src/core/proto/date.js +++ b/src/core/proto/date.js @@ -499,7 +499,46 @@ Date.parseDateTime = function (str, fmt) { }; Date.getDate = function () { - var dt = new (Function.prototype.bind.apply(Date, BI.concat([null], [].slice.apply(arguments))))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone) && (arguments.length === 0 || (arguments.length === 1 && BI.isNumber(arguments[0])))) { var localTime = dt.getTime(); var localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 @@ -511,7 +550,46 @@ Date.getDate = function () { }; Date.getTime = function () { - var dt = Function.prototype.bind.apply(Date.getDate, BI.concat([null], [].slice.apply(arguments)))(); + var length = arguments.length; + var args = arguments; + var dt; + switch (length) { + // new Date() + case 0: + dt = new Date(); + break; + // new Date(long) + case 1: + dt = new Date(args[0]); + break; + // new Date(year, month) + case 2: + dt = new Date(args[0], args[1]); + break; + // new Date(year, month, day) + case 3: + dt = new Date(args[0], args[1], args[2]); + break; + // new Date(year, month, day, hour) + case 4: + dt = new Date(args[0], args[1], args[2], args[3]); + break; + // new Date(year, month, day, hour, minute) + case 5: + dt = new Date(args[0], args[1], args[2], args[3], args[4]); + break; + // new Date(year, month, day, hour, minute, second) + case 6: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + // new Date(year, month, day, hour, minute, second, millisecond) + case 7: + dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + break; + default: + dt = new Date(); + break; + } if(BI.isNotNull(Date.timeZone)) { return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000; } diff --git a/src/polyfill/function.js b/src/polyfill/function.js new file mode 100644 index 000000000..91570345a --- /dev/null +++ b/src/polyfill/function.js @@ -0,0 +1,29 @@ +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (typeof this !== 'function') { + // closest thing possible to the ECMAScript 5 + // internal IsCallable function + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof fNOP + ? this + : oThis, + // 获取调用时(fBound)的传参.bind 返回的函数入参往往是这么传递的 + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + // 维护原型关系 + if (this.prototype) { + // Function.prototype doesn't have a prototype property + fNOP.prototype = this.prototype; + } + fBound.prototype = new fNOP(); + + return fBound; + }; +} \ No newline at end of file