(Open Source) Examples of JavaScript Prototypical OO (Open Source) Examples of JavaScript Prototypical OO javascript javascript

(Open Source) Examples of JavaScript Prototypical OO


You will not find it.

I went looking for this sort of thing a while ago, and this is what I found: the Self Paper Organizing Programs Without Classes (Look at Citeseer for a PDF version.) This paper discusses the best practices for Self, the original prototypal language, and the best practice is to use the "traits object idiom", which is to have your objects inherit from "traits objects" that contain only methods, and no object specific data. In other words, an object that is suspiciously like a class.

Even the original prototypal language emulates classes.


Have you taken a look at OMeta/JS? OMeta is an experimental research pattern matching language based on Smalltalk and Self. OMeta/JS is an implementation in javascript using prototypical OO.

It is well commented and documented with many examples. It is also on Github.

http://tinlizzie.org/ometa-js/

https://github.com/alexwarth/ometa-js

Edit: OMeta is the result of Alexander Warth's PhD disertation.


I'm not exactly sure what you are looking for, but my current framework allows you to program in OO fashion like so:

Cin.define({    name: 'MyApp.Logger',    extends: 'Cin.Component',    implements: ['MyApp.ILogger'],    mixes: {        SomeMixin: 'MyApp.SomeMixin'    },    init: function() {    },    method: function() {    },    statics: {        staticMethod: function() {}    }});

And then you can write code like:

var instance = new MyApp.Logger();instance.method();MyApp.Logger.staticMethod();

I am not trying to emulate classical OO here. I am trying to make a convenient and useful way to declare inheritance, mixins, interfaces, and general OO concepts so that it becomes easy for the developer to write such OO code. This also gives me the chance to finish my auto loading component so that you no longer take care of dependencies and you can make custom builds and enjoy faster development thanks to not needing to load 100 scripts per each page load.

If you want to learn prototypical OO concepts, I think you should write some kind of inheritance system. Take a look at Dojo Toolkit or ExtJS. A good thing to remember is that Prototype-based systems twist and mangle, they are more powerful than Class-based OO languages. In my opinion, there is no single right way to write prototypal code.

I'm afraid though that most if not all inheritance systems might look like they emulate classical OO. In my opinion, my framework does not, but then it's not even finished.