> The object exemplar approach is just like self or selfish, except that it
> builds upon features that are already in JS. Specifically, it uses the new
> operator instead of a new method and it names the initialization method
> "constructor" in order to tie into the object construction mechanisms that
> already exist in JS.
I’m trying to summarize, let me know if I made any mistakes:
With the new new approach, we will have four kinds of exemplars (which are,
roughly, “object factories”):
1. Object literals
2. Function exemplars (constructor exemplars?)
3. Object exemplars (prototype exemplars?)
4. Object.create()
The proto operator lets us use inheritance between any two #2 or #3 exemplars.
That ensures compatibility with legacy code. Since instanceof works for both
kinds of examplars as well, the only possible hazard that is left is function
exemplar code trying to access ObjectExamplar.prototype, e.g. to add new
methods.
Object exemplar example:
const Person = {
constructor(name) {
this.name = name;
},
describe() {
return "Person called "+this.name;
}
};
const Employee = Person <| {
constructor(name, title) {
super.constructor(name);
this.title = title;
},
describe() {
return super.describe()+" ("+this.title+")";
}
};
let jane = new Employee();
console.log(jane instanceof Employee); // true
If object exemplars were to become part of ES.next, we would not need class
literals.
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss