Douglas Crockford has a really good talk on "The Better Parts" of ES6. Among other things, he encourages a move away from prototypal inheritance in favor of class free OOP .
Here he says he stopped using new
, Object.create
, and this
, but didn't really explain an alternative. Could anyone fill me in on how that might look?
You should watch the whole video, he explains it at later in the video .
function constructor(spec) {
let {member} = spec,
{other} = other_constructor(spec),
method = function () {
// accesses member, other, method, spec
};
return Object.freeze({
method,
other
});
}
It's the revealing module pattern returning a frozen object .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.