From 825d7df118b3b0c830e5328ed1d846f4b33c3671 Mon Sep 17 00:00:00 2001 From: Fabio Massaioli Date: Thu, 21 May 2015 11:07:11 +0200 Subject: [PATCH] Use Object.defineProperty to define property aliases Fix #1 --- src/compatibility.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/compatibility.js b/src/compatibility.js index b307e5e..9869cd9 100644 --- a/src/compatibility.js +++ b/src/compatibility.js @@ -2,11 +2,14 @@ * @param {Object} object * @private */ -function proxyWebkitMethods(object) { +function proxyWebkitProperties(object) { var isWebkit = /^webkit/; - Object.getOwnPropertyNames(object.prototype).forEach(function(method) { - if (isWebkit.test(method)) { - object.prototype[method[6].toLowerCase()+method.slice(7)] = object.prototype[method]; + Object.getOwnPropertyNames(object.prototype).forEach(function(property) { + if (isWebkit.test(property)) { + Object.defineProperty(object.prototype, property[6].toLowerCase() + property.slice(7), { + get: function() { return this[property]; }, + set: function(value) { this[property] = value; } + }); } }); } @@ -21,9 +24,9 @@ function checkFileAPI() { window['FileReader'] = window['FileReader'] || window['webkitFileReader'] || undefined; if (Blob && File && FileReader) { - proxyWebkitMethods(window['Blob']); - proxyWebkitMethods(window['File']); - proxyWebkitMethods(window['FileReader']); + proxyWebkitProperties(window['Blob']); + proxyWebkitProperties(window['File']); + proxyWebkitProperties(window['FileReader']); return true; } else { @@ -39,7 +42,7 @@ function checkDataViewAPI() { window['DataView'] = window['DataView'] || window['webkitDataView'] || undefined; if (DataView) { - proxyWebkitMethods(window['DataView']); + proxyWebkitProperties(window['DataView']); return true; } else {