var output = function (msg) { var n = document.createElement('div'); n.innerText = msg; document.getElementById('message').appendChild(n); }; (function () { "use strict"; class Person { constructor(name, age) { this.name = name; this.age = age; } getName() { return this.name; } sayHello() { return 'Hello I\'m ' + this.getName(); } } var alice = new Person('Alice', 7); output(alice.sayHello()); class Employee extends Person { constructor(name, age, salary) { super(name, age); this.salary = salary; } sayHello() { return super.sayHello() + ' (salary:' + this.salary + ')'; } } var bob = new Employee('Bob', 25, 1234); output(bob.sayHello()); // 'this' is not lexical. var hello = bob.sayHello; try { output(hello()); } catch (e) { output('Error: ' + e); } }());
<div id="message"></div>