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 privadas = new WeakMap();
function Persona() {
// Inicializamos el objeto
privadas.set(this, {});
privadas.get(this).otraPrivada = "Variable inaccesible desde fuera";
}
Persona.prototype = {
guardarSecreto: function(susurro) {
privadas.get(this).secreto = susurro;
},
revelarSecreto: function() {
return privadas.get(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());