Mixins vs. Traits

Mixins may contain state, (traditional) traits don’t. Mixins use “implicit conflict resolution”, traits use “explicit conflict resolution” Mixins depends on linearization, traits are flattened. Lecture about traits ad 1. In mixins you can define instance variables. Traits do not allow this. The state must be provided by the composing class (=class using the traits) ad … Read more

Less and Bootstrap: how to use a span3 (or spanX [any number]) class as a mixin?

New Answer (requires LESS 1.4.0) What you actually desire is something known as extending in LESS and SASS terminology. For example, you want an HTML element (just an example)… <div class=”myclass”></div> …to fully behave as if it had a span3 class from bootstrap added to it, but without actually adding that class in the HTML. … Read more

Mixin vs inheritance

A mixin is typically used with multiple inheritance. So, in that sense, there’s “no difference”. The detail is that a mixin is rarely useful as a standalone object. For example, say you have a mixin named “ColorAndDimension”, which adds a color property and width and height. Now, you could add ColorAndDimension to a, say, Shape … Read more

How to define a dynamic mixin or function name in SASS?

Variable interpolation in @mixins does not appear to be supported currently. The SASS documentation calls this #{} interpolation and describes it like this: Interpolation: #{} You can also use SassScript variables in selectors and property names using #{} interpolation syntax: $name: foo; $attr: border; p.#{$name} { #{$attr}-color: blue; } Per the documentation, interpolation of variable … Read more

CSS property as SASS mixin value [duplicate]

If you want to use variables as property names you need to use string interpolation – #{$var}. So this should work: [class*=”shift”] { $sft-o: 10px; @mixin shift_stp($val) { &[class*=”_sml”]{ #{$val}: $sft-o; } &[class*=”_mid”]{ #{$val}: $sft-o * 2; } &[class*=”_big”]{ #{$val}: $sft-o * 3; } } &[class*=”_m”]{ @include shift_stp(margin); } &[class*=”_p”]{ @include shift_stp(padding); } } DEMO … Read more

How to use mixins properly in Javascript

A mixin is just a different conceptual idea, of how to organize code and inheritance. You can of course combine it with using classical or prototypal inheritance, but it also works stand-alone, so to speak. For instance, instead of creating “delegated” object properties/lookups (like prototypal inheritance), we would truly “form” new stand-alone objects, from multiple … Read more

Implement Mixin In Java? [closed]

You could use CGLIB for that. The class Mixin is able to generate a dynamic class from several interfaces / object delegates: static Mixin create(java.lang.Class[] interfaces, java.lang.Object[] delegates) static Mixin create(java.lang.Object[] delegates) static Mixin createBean(java.lang.Object[] beans)