Property descriptors as ES6 Maps

Brandon Benvie brandon at brandonbenvie.com
Thu Nov 1 09:45:06 PDT 2012


Another argument against using maps is it can actually be pretty useful to
use the features that prototypal inheritance and the object model provides.

function Descriptor(configurable, enumerable){
  this.configurable = configurable;
  this.enumerable = enumerable;
}

Descriptor.prototype = {
  configurable: undefined,
  enumerable: undefined,
  inerit: function inerit(){
    return Object.create(this);
  }
};

function DataDescriptor(value, writable, enumerable, configurable){
  this.value = value;
  this.writable = writable;
  this.enumerable = enumerable;
  this.configurable = configurable;
}
DataDescriptor.prototype = new Descriptor
DataDescriptor.prototype.value = undefined;
DataDescriptor.prototype.writable = undefined;

function AccessorDescriptor(get, set, enumerable, configurable){
  this.get = get;
  this.set = set;
  this.enumerable = enumerable;
  this.configurable = configurable;
}
AccessorDescriptor.prototype = new Descriptor;
AccessorDescriptor.prototype.get = undefined;
AccessorDescriptor.prototype.set = undefined;

function Value(value){
  this.value = value;
}
Value.prototype = new DataDescriptor(undefined, true, true, true);

function HiddenValue(value){
  this.value = value;
}
Value.prototype = new DataDescriptor(undefined, true, false, true);

function Accessor(get, set){
  this.get = get;
  this.set = set;
}
Accessor.prototype = new AccessorDescriptor(undefined, undefined, true,
true);

function Getter(get){
  this.get = get;
}
Getter.prototype = new Accessor;

function Setter(set){
  this.set = set;
}
Setter.prototype = new Accessor;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121101/040600a5/attachment.html>


More information about the es-discuss mailing list