Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Open Source) Examples of JavaScript Prototypical OO

Bounty Edit:

I'm looking for code written in a pure prototypical OO paradigm (think Self). Not a mixture of prototypical OO and classical OO. I don't want to see generic OO wrappers but simply usage of prototypical OO techniques and only prototypical OO techniques.

Reference Related Question:

Prototypical OO in JavaScript

In the above question I mainly focused on

Can write prototypical OO like this?

Do we need constructors and initialization logic, What are the alternatives?

New question:

Basically are there any good examples of javascript prototypical OO in large open source projects?

Clarification:

I will have to clarify what I mean with prototypical OO :

  • There are no classes. There are only Objects.
  • There is zero emulation of the concepts of classes, again there is only objects and cloning objects to create new objects.

Further Clarification of Prototypical OO:

The difference between prototypical OO in JavaScript and classical OO emulation is a very grey area. It's not that I value avoiding classical OO. I want to learn prototypical OO in an academic fashion in it's own right, without learning the (probably more optimum) combination of classical OO emulation and prototypical OO.

This is why I "ban" classes, just so that I can see these techniques in a pure fashion and extend my own OO tool kit.

Examples:

Popular examples like jQuery fail to meet the second criteria. The jQuery object is one big class emulation. It focuses on creating new objects from a class rather then cloning existing objects.

If I actually knew any example of using "pure" prototypical OO I would have shown you. I believe 99% of JavaScript OO is too heavily influenced by classical emulation.

Bonus points

If

  • It's well comented / documented
  • Has unit tests
  • Is on github.

I will also accept articles / tutorials and examples on how to write prototypical OO code that goes beyond your trivial hello world application.

like image 370
Raynos Avatar asked Jun 30 '11 11:06

Raynos


People also ask

Should I use OOP in JavaScript?

So… when should you use OOP? # If you need a simple guideline: whenever you're going to being creating more than one or two of an item that has some shared properties and some unique ones.

What is model in JavaScript?

Models are data structures that we use to define the shape of our data. You might also know them as objects, as in Object Oriented Programming, but in JavaScript everything is an Object, so it's not clear that we are talking about something specific if we just call them Objects.

What is prototype in JavaScript stackoverflow?

1. 13. -1: prototype is a property of constructor functions, not instances, ie your code is wrong!

What is .this in JavaScript?

What is this? In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object.


2 Answers

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.

like image 174
Sean McMillan Avatar answered Oct 07 '22 06:10

Sean McMillan


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.

like image 37
jsherer Avatar answered Oct 07 '22 08:10

jsherer