From 23ee50349f1e2acb9e4c643f0d3339adce3e91ef Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Wed, 8 Jan 2014 15:27:39 +0100 Subject: [PATCH] =?UTF-8?q?Avoid=20IE8=E2=80=99s=20broken=20`Object.define?= =?UTF-8?q?Property`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IE 8 only supports `Object.defineProperty` on DOM elements, so detect that and fall back. --- fromcodepoint.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fromcodepoint.js b/fromcodepoint.js index 552390d..b7d24d8 100644 --- a/fromcodepoint.js +++ b/fromcodepoint.js @@ -1,6 +1,15 @@ /*! http://mths.be/fromcodepoint v0.1.0 by @mathias */ if (!String.fromCodePoint) { (function() { + var defineProperty = (function() { + // IE 8 only supports `Object.defineProperty` on DOM elements + try { + var object = {}; + var $defineProperty = Object.defineProperty; + var result = $defineProperty(object, object, object) && $defineProperty; + } catch(error) {} + return result; + }()); var stringFromCharCode = String.fromCharCode; var floor = Math.floor; var fromCodePoint = function() { @@ -40,8 +49,8 @@ if (!String.fromCodePoint) { } return result; }; - if (Object.defineProperty) { - Object.defineProperty(String, 'fromCodePoint', { + if (defineProperty) { + defineProperty(String, 'fromCodePoint', { 'value': fromCodePoint, 'configurable': true, 'writable': true