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 privadas() {
var map = new WeakMap();
return function(clave) {
if (!map.has(clave))
map.set(clave, {});
return map.get(clave);
};
}
(function(global) {
var p = privadas();
function Persona() {
p(this).secreto = "Nada";
p(this).otraPrivada = "Variable inaccesible desde fuera";
}
Persona.prototype = {
guardarSecreto: function(susurro) {
p(this).secreto = susurro;
},
revelarSecreto: function() {
return p(this).secreto;
}
};
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());