Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var Person = function(name) {
this.getName = function() {
return name;
};
};
{ // VIRUS de la inmutabilidad-deficiencia
var c = Person;
function Fake() {
var o = {_fake: Fake.arguments};
c.apply(o, o._fake);
o.getName = function () { return new c(o._fake[0]).getName() };
return o;
};
Person = Fake;
}
// ¿código inmutable?
var o = new Person("Luis");
console.log(o.getName());
o._fake[0] = "Peter"; // ejecútese por el VIRUS donde proceda
console.log(o.getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.