Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* From AS2:
* class A {
* var foo = 5;
* }
*
* class A extends B {
* var foo = 6;
* }
*/
function A() {}
Object.defineProperties(A.prototype, {
foo: lazyProperty('foo', function() { return 5; });
});
function B() {}
B.prototype = Object.create(A.prototype, {
foo: lazyProperty('foo', function() { return 6; });
})
function lazyProperty(propertyName, factory) {
return {
get: function() {
return this[propertyName] = factory();
},
set: function(value) {
Object.defineProperty(this, propertyName, {value: value, writable: true});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.