termi / es6-transpiler

Tomorrow's JavaScript syntax today
Other
216 stars 18 forks source link

Class inheritance don’t work in IE #6

Closed sapegin closed 10 years ago

sapegin commented 10 years ago

Source code:

class Animal {
    constructor() {
        this.test = 'test';
        this.print();
    }
    print() {
        console.log(this.test);
    }
}

var animal = new Animal();

class Ferret extends Animal {
    print() {
        console.log('inherited');
        super.print();
    }
}

var ferret = new Ferret();
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>ES6</title>
</head>
<body>
    <script>
    Object.assign = function(target, source) {
        for (var prop in source) {
            if (source.hasOwnProperty(prop)) {
                target[prop] = source[prop];
            }
        }
        return target;
    };
    </script>
    <script src="script.js"></script>
</body>
</html>

IE8:

 test 
SCRIPT438: Object doesn't support property or method 'create' 
transpiler.js, line 14 character 111

IE9 and IE10:

test 
SCRIPT5007: Invalid descriptor for property '__proto__' 
transpiler.js, line 14 character 111
termi commented 10 years ago

You need to have an Object.create polyfill for IE8

termi commented 10 years ago

Polyfill for Object.assign #11

For now, don't want to adding polyfill for Object.create. es5-shim has it and tons of other good stuff

termi commented 10 years ago

Added important about Object.[assign/create] https://github.com/termi/es6-transpiler/commit/81a0c04551510533eb2e179127cfa64c5a1e1087