Object.prototype.takeGiftFromSauron = function() {
function makeRingWraith() {
var me = this;
Object.getOwnPropertyNames(me).forEach(function(name){
if (name === 'Object') return;
var bag = Object.getOwnPropertyDescriptor(me,name);
if (bag.configurable) delete me[name];
else if (bag.writable) me[name] = null;
else alert('damn '+name+'!');
});
}
Object.defineProperty(this,'ring',{get:makeRingWraith});
return this;
}
var Frodo = Object.defineProperties({},{
'coins':{value:3,enumerable:true},
'soul': {value:'simple',enumerable:true,configurable:true},
'sword':{value:'elfic',enumerable:true,configurable:true},
'cape': {value:'brown',enumerable:true,writable:true}
});
// Frodo do you like this innocent ring?
Frodo.takeGiftFromSauron();
// Wear the ring Frodo!!
alert(Frodo.ring);
// Surprise! Little avaricious hobbit, where are your soul and your elfic sword?
It works! Blogger parece aceptar cualquier cosa. Empieza gustarme :D
No hay comentarios:
Publicar un comentario