Skip to content

Commit

Permalink
Avoid IE8’s broken Object.defineProperty
Browse files Browse the repository at this point in the history
IE 8 only supports `Object.defineProperty` on DOM elements, so detect that and fall back.
  • Loading branch information
mathiasbynens committed Jan 8, 2014
1 parent 02c8ae5 commit 23ee503
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions 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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23ee503

Please sign in to comment.