Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Last active December 19, 2015 00:19
Show Gist options
  • Save ryasmi/5868142 to your computer and use it in GitHub Desktop.
Save ryasmi/5868142 to your computer and use it in GitHub Desktop.
var x = (function () {
var a = function () {
return s;
};
var b = function () {
return s.a();
};
var s = {a: a, b: b, name: "x"};
return s;
}());
var y = (function () {
var a = function () {
return s;
};
var b = function () {
return s.a();
};
var s = {a: a, b: b, name: "y"};
return s;
}());
var z = (function () {
var a = function () {
return s;
};
var b = function () {
return s.a();
};
var s = {a: a, b: b, name: "z"};
return s;
}());
x.a() === x; // true.
x.b() === x; // true.
y.a() === y; // true.
y.b() === y; // true.
z.a() === z; // true.
z.b() === z; // true.
z.a = y.b;
y.a = x.b;
x.a() === x; // true.
x.b() === x; // true.
y.a() === x; // true.
y.b() === x; // true.
z.a() === x; // true.
z.b() === x; // true.
var x = (function () {
var a = function () {
return s;
};
var s = {a: a, name: "x"};
return s;
}());
var y = (function () {
var a = function () {
return s;
};
var s = {a: a, name: "y"};
return s;
}());
var z = (function () {
var a = function () {
return s;
};
var s = {a: a, name: "z"};
return s;
}());
x.a() === x; // true.
y.a() === y; // true.
z.a() === z; // true.
z.a = function () {return y.a();};
y.a = function () {return x.a();};
x.a() === x; // true.
y.a() === x; // true.
z.a() === x; // true.
var myConstructor = (function () {
var property = function (self, value) {
return function (given) {
value = given ? given : value;
return given ? self : value;
};
};
var objProperty = function (self, obj) {
var props = {
self: self
};
Object.keys(obj).forEach(function (key) {
props[key] = property(props, obj[key]);
});
return props;
};
var MyConstructor = function () {
var self = this;
self.props = objProperty(self, {a: 10, b: 11});
return self;
};
return function () {
return new MyConstructor();
}
}());
var a = myConstructor();
var b = myConstructor();
a.props.self.props.a(12).a() === 12; // True.
b.props.a() === 10; // True.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment