Skip to content

Commit 825d7df

Browse files
committed
Use Object.defineProperty to define property aliases
Fix #1
1 parent 6abf0ef commit 825d7df

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/compatibility.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
* @param {Object} object
33
* @private
44
*/
5-
function proxyWebkitMethods(object) {
5+
function proxyWebkitProperties(object) {
66
var isWebkit = /^webkit/;
7-
Object.getOwnPropertyNames(object.prototype).forEach(function(method) {
8-
if (isWebkit.test(method)) {
9-
object.prototype[method[6].toLowerCase()+method.slice(7)] = object.prototype[method];
7+
Object.getOwnPropertyNames(object.prototype).forEach(function(property) {
8+
if (isWebkit.test(property)) {
9+
Object.defineProperty(object.prototype, property[6].toLowerCase() + property.slice(7), {
10+
get: function() { return this[property]; },
11+
set: function(value) { this[property] = value; }
12+
});
1013
}
1114
});
1215
}
@@ -21,9 +24,9 @@ function checkFileAPI() {
2124
window['FileReader'] = window['FileReader'] || window['webkitFileReader'] || undefined;
2225

2326
if (Blob && File && FileReader) {
24-
proxyWebkitMethods(window['Blob']);
25-
proxyWebkitMethods(window['File']);
26-
proxyWebkitMethods(window['FileReader']);
27+
proxyWebkitProperties(window['Blob']);
28+
proxyWebkitProperties(window['File']);
29+
proxyWebkitProperties(window['FileReader']);
2730

2831
return true;
2932
} else {
@@ -39,7 +42,7 @@ function checkDataViewAPI() {
3942
window['DataView'] = window['DataView'] || window['webkitDataView'] || undefined;
4043

4144
if (DataView) {
42-
proxyWebkitMethods(window['DataView']);
45+
proxyWebkitProperties(window['DataView']);
4346

4447
return true;
4548
} else {

0 commit comments

Comments
 (0)