4 ms·
Doesn't surprise me. If I look how people build class systems with JS before ES2015, I'd guess all languages that have closures and higher order functions could
by k__ 7y ago
Doesn't surprise me. If I look how people build class systems with JS before ES2015, I'd guess all languages that have closures and higher order functions could invent OOP. Maybe that isn't even needed IDK.
- jrimbault 7y agoPeople did it in C way back, with usually structs containing their value and a table of functions associated with them (vtable). You can do "inheritance" by having the parent struct be the first member of the child struct. You can do all sorts of fun stuff (composition is easy of course, injection also). The only thing of note, is that you can't "curry" the source, you'll always have to give the "source/this/self" object as an argument to the method. This isn't any different from how you could in python, for example, do : `"my string".split(" ")` or `str.split("my string", " ")`. (just some fun little experiments I did last year https://github.com/jRimbault/DataStructures/blob/master/lib/struct/String.h https://github.com/jRimbault/DataStructures/blob/master/lib/..., there isn't any vtable, but it does show a string "class/struct" with all private fields, and methods for creating, managing those objects)
- mistrial9 7y agoone-deep tables of function pointers with some kind of sensible model on why sets of function pointers are there.. many, many useful applications.
- marmaduke 7y ago> You can do "inheritance" by having the parent struct be the first member of the child struct. You can do all sorts of fun stuff I have done this, 'fun' is not how I describe the result to colleagues
- jrimbault 7y agoAlright, -fun +nightmarish. Still fun though.
- dboreham 7y agoAlso: in assembly, machine code.
- ChrisSD 7y agoBut Javascript was designed for OOP from the beginning, albeit not with classes.
- k__ 7y agoTrue. But you wouldn't have to use prototypes to get class-like behavior.