JSFiddle - React, Tailwind, and code Playground
by amatiasq
HTML
<script src="http://amatiasq.com/fiddle-console.js"></script>
<script src="http://amatiasq.com/weakmap-polyfill.js"></script>
JavaScript
(function(global) {
var secreto = new WeakMap();
function Persona() { }
Persona.prototype = {
guardarSecreto: function(susurro) {
secreto.set(this, susurro);
},
revelarSecreto: function() {
// Si no tenemos ningún secreto
if (!secreto.has(this))
return "Nada";
else
return secreto.get(this);
}
};
global.Persona = Persona;
})(this);
var pepe = new Persona();
var maria = new Persona();
pepe.guardarSecreto('estás en matrix');
console.log("Secreto de María: " + maria.revelarSecreto());
console.log("Secreto de Pepe: " + pepe.revelarSecreto());