What are some languages that currently support mixins?
Well obviously开发者_开发知识库 Ruby and Sass, but what are some other ones?
Wiki has a list
http://en.wikipedia.org/wiki/Mixin#Programming_languages_that_use_mixins
To quote:
Programming languages that use mixins
Other than Flavors and CLOS (a part of Common Lisp), some languages that use mixins are:
* ColdFusion (Class based using includes and Object based
by assigning methods from one object to another at runtime)
* Curl(with Curl RTE)
* D (called "template mixins")
* Factor[citation needed]
* Fantom
* Ioke
* JavaFX Script
* JavaScript
* Object REXX
* OpenLaszlo
* Perl[3]
* PLT Scheme (mixins documentation)
* Python
* Ruby
* Scala
* Smalltalk
* Strongtalk
* Vala
* Visual Dataflex
* XOTcl/TclOO (object systems for Tcl)[4]
Some languages like ECMAScript (commonly referred to as JavaScript) do not support mixins on the language level, but can easily mimic them by copying methods from one object to another at runtime, thereby "borrowing" the mixin's methods. Note that this is not possible with statically typed languages, where an object's signature is fixed at compile time.
Both versions 1 and 2 of D support mixins.
Perl's Roles could be called mixins.
_why's potion language leaps to mind. The idea is that objects have state, and methods. In most languages, state happens in the object, methods happen on the class. In potion, objects have only state, methods are completely handled with mixins.
To quote from the readme
EVERYTHING IS AN OBJECT. EVEN MIXINS ARE OBJECTS. AND, OF COURSE, CLOSURES ARE OBJECTS.
However, OBJECTS AREN'T EVERYTHING. THEY ARE USELESS WITHOUT MIXINS.
on a side note, I miss why. we need more people doing wild stuff like this
Well, Flavors of course. This morphed into CLOS.
JavaScript supports them. You can add functions/fields to an object's prototype anytime.
精彩评论