Object.create(proto, props)
ha due argomenti
proto
— the object which should be the prototype of the newly-created object.
props
(optional) — an object whose properties specify property descriptors to be added to the newly-created object, with the corresponding property names.
Il formato per l'oggetto props
è definita here.
In breve, le opzioni disponibili per ogni descrittore di proprietà sono queste:
{
configurable: false, // or true
enumerable: false, // or true
value: undefined, // or any other value
writable: false, // or true
get: function() { /* return some value here */ },
set: function (newValue) { /* set the new value of the property */ }
}
Il problema con il vostro codice è che i descrittori di proprietà che avete definito non sono oggetti.
Ecco un esempio di un corretto utilizzo di descrittori di proprietà:
var test = Object.create(null, {
ex1: {
value: 1,
writable: true
},
ex2: {
value: 2,
writable: true
},
meth: {
get: function() {
return 'high';
}
},
meth1: {
get: function() {
return this.meth;
}
}
});
fonte
2016-06-07 07:26:52
meth rendimenti elevati - ho pianto. XD – evolutionxbox