3 ms·
I've also seen very simple object systems built purely using closures in Lisp. I can't remember where I've seen it, but it usually involves the bank account exa
by jwdunne 11y ago
I've also seen very simple object systems built purely using closures in Lisp. I can't remember where I've seen it, but it usually involves the bank account example. Since no other Lisp features were involved,until you start glossing over with macros, this could be replicated in JS. It'd look strange but it's certainly possible, e.g:
var savings = account(200);
savings('deposit')(200);
console.log(savings('amount')); // should print 400
savings('withdraw')(200);
console.log(savings('amount')); // should print 200
If you can build an OO system in terms of lambdas and closures, does it mean the two are incompatible? I don't think so.
- spdegabrielle 11y agoI think it's this one http://okmij.org/ftp/Scheme/oop-in-fp.txt http://okmij.org/ftp/Scheme/oop-in-fp.txt
- spdegabrielle 11y agoBetter link http://okmij.org/ftp/Scheme/#pure-oo http://okmij.org/ftp/Scheme/#pure-oo