-
-
Save kl0tl/fb1d4032d805c255b943 to your computer and use it in GitHub Desktop.
Very simple class alternative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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