Skip to content

Instantly share code, notes, and snippets.

@kl0tl
Last active August 29, 2015 14:02
Show Gist options
  • Save kl0tl/fb1d4032d805c255b943 to your computer and use it in GitHub Desktop.
Save kl0tl/fb1d4032d805c255b943 to your computer and use it in GitHub Desktop.
Very simple class alternative
/*
var Foo = {
__proto__: K,
method: function () {}
};
var Bar = {
__proto__: Foo
};
var bar = Bar.new();
Bar.isPrototypeOf(bar) === true;
Foo.isPrototypeOf(bar) === true;
K.isPrototypeOf(bar) === true;
typeof bar.method === 'function';
*/
var K = {
constructor: function () {},
new: function () {
var o, ret;
o = Object.create(this);
ret = o.constructor.apply(o, arguments);
if (ret && typeof ret === 'object') {
return ret;
}
return o;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment