Created
February 1, 2015 06:30
-
-
Save deepak/0940d26cefbe09851656 to your computer and use it in GitHub Desktop.
calling method in superclass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//output | |
repl: Line 30: Direct super call is illegal in non-constructor, use super.doWork() instead | |
28 | | |
29 | doWork() { | |
> 30 | let person = super(); | |
| ^ | |
31 | return `${person} paid`; | |
32 | } | |
33 | } | |
//generated javascript | |
"use strict"; | |
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; | |
var Employee = (function () { | |
function Employee(name) { | |
this._name = name; | |
} | |
_prototypeProperties(Employee, null, { | |
name: { | |
get: function () { | |
return this._name; | |
}, | |
set: function (newValue) { | |
this._name = newValue; | |
}, | |
configurable: true | |
} | |
}); | |
return Employee; | |
})(); | |
var greg = new Employee("greg"); | |
console.log(greg.name); | |
greg.name = "test"; | |
console.log(greg.name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// es6 javascript | |
class Person { | |
constructor(name) { | |
this._name = name; | |
} | |
get name() { | |
return this._name; | |
} | |
set name(newValue) { | |
this._name = newValue; | |
} | |
doWork() { | |
return "free"; | |
} | |
} | |
class Employee extends Person { | |
constructor(name, title) { | |
super(name); | |
this.title = title; | |
} | |
set title(newTitle) { | |
this._title = newTitle; | |
} | |
doWork() { | |
let person = super(); | |
return `${person} paid`; | |
} | |
} | |
let alex = new Person("alex"); | |
let greg = new Employee("greg", "dev"); | |
console.log(alex.doWork()); | |
console.log(greg.doWork()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//output | |
free | |
undefined paid | |
// generated javascript | |
$traceurRuntime.ModuleStore.getAnonymousModule(function() { | |
"use strict"; | |
var Person = function Person(name) { | |
this._name = name; | |
}; | |
($traceurRuntime.createClass)(Person, { | |
get name() { | |
return this._name; | |
}, | |
set name(newValue) { | |
this._name = newValue; | |
}, | |
doWork: function() { | |
return "free"; | |
} | |
}, {}); | |
var Employee = function Employee(name, title) { | |
$traceurRuntime.superConstructor($Employee).call(this, name); | |
this.title = title; | |
}; | |
var $Employee = Employee; | |
($traceurRuntime.createClass)(Employee, { | |
set title(newTitle) { | |
this._title = newTitle; | |
}, | |
doWork: function() { | |
var person = $traceurRuntime.superConstructor($Employee).call(this); | |
return (person + " paid"); | |
} | |
}, {}, Person); | |
var alex = new Person("alex"); | |
var greg = new Employee("greg", "dev"); | |
console.log(alex.doWork()); | |
console.log(greg.doWork()); | |
return {}; | |
}); | |
//# sourceURL=traceured.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
6to5
gave a better error message