Skip to content

Commit

Permalink
Use Object.defineProperty to define property aliases
Browse files Browse the repository at this point in the history
Fix #1
  • Loading branch information
fbbdev committed May 21, 2015
1 parent 6abf0ef commit 825d7df
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
});
}
});
}
Expand All @@ -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 {
Expand All @@ -39,7 +42,7 @@ function checkDataViewAPI() {
window['DataView'] = window['DataView'] || window['webkitDataView'] || undefined;

if (DataView) {
proxyWebkitMethods(window['DataView']);
proxyWebkitProperties(window['DataView']);

return true;
} else {
Expand Down

0 comments on commit 825d7df

Please sign in to comment.