mixins

What are the practical differences between Mixins and Inheritance in Javascript?

六眼飞鱼酱① 提交于 2019-12-10 11:32:24
问题 Is just (simulating) multiple inheritance the only advantage of mixing: Object.assign( MyClassA.prototype, MyMixinB ) versus inheritance class MyClass extends MyClassB { // MyClassB = class version of MyMixinB in ES6 Javascript? Thanks 回答1: There will be not that one short answer. The practicality comes with the many different technical approaches (and how one combines them) that JavaScript (JS) does offer for building type/object systems. First, as the OP (original poster) already is aware

Modify Bootstrap LESS files to use an ID selector

£可爱£侵袭症+ 提交于 2019-12-10 10:04:02
问题 Briefly, what I'm trying to do is apply a custom ID selector on top of Bootstrap.CSS so that I don't break other CSS on a website. So this : .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col

Groovy Mixins?

↘锁芯ラ 提交于 2019-12-10 01:58:55
问题 I'm trying to mix-in a class in my Groovy/Grails app, and I'm using the syntax defined in the docs, but I keep getting an error. I have a domain class that looks like this: class Person { mixin(ImagesMixin) // ... } It compiles fine, but for some reason it won't work. The file containing ImagesMixin is located in my /src/groovy/ directory. I've tried it using Groovy versions 1.5.7 and 1.6-RC1 without any luck. Does anyone know what I'm doing wrong? stacktrace: 2008-12-30 17:58:25.258::WARN:

How to get the `self` to refer to a my class inside a Mixin module (even if it is stated outside the context of a method)?

混江龙づ霸主 提交于 2019-12-10 00:25:45
问题 I am using Ruby on Rails 3.2.2. I have implemented a Mixin module for a Article model class and I would like to get the self to refer to Article (even, for example, if it stated outside the context of a method). That is, I am trying to make the following: module MyModule extend ActiveSupport::Concern # Note: The following is just a sample code (it doesn't work for what I am # trying to accomplish) since 'self' isn't referring to Article but to the # MyModule itself. include MyModule:

Intersection of mapped types

人走茶凉 提交于 2019-12-09 18:58:05
问题 Consider the following: type Properties = { foo: { n: number }; bar: { s: string }; baz: { b: boolean }; }; declare function retrieveValues<K extends keyof Properties>(add?: K[]): Pick<Properties, K>[K]; // what happens const x: { n: number } | { s: string } = retrieveValues(['foo', 'bar']); // what I'm really trying to express (type error) const y: { n: number } & { s: string } = retrieveValues(['foo', 'bar']); Is there a way to get an intersection of the properties of Pick<Properties, K> ?

In Python can one implement mixin behavior without using inheritance?

三世轮回 提交于 2019-12-09 07:20:23
问题 Is there a reasonable way in Python to implement mixin behavior similar to that found in Ruby -- that is, without using inheritance? class Mixin(object): def b(self): print "b()" def c(self): print "c()" class Foo(object): # Somehow mix in the behavior of the Mixin class, # so that all of the methods below will run and # the issubclass() test will be False. def a(self): print "a()" f = Foo() f.a() f.b() f.c() print issubclass(Foo, Mixin) I had a vague idea to do this with a class decorator,

LESS mixins with multiple arguments

老子叫甜甜 提交于 2019-12-09 06:09:27
I have this little mixin set up: .linear-gradient(@direction:top, @color1:#fff, @color2:#000) { background-image: -webkit-linear-gradient(@direction, @color1, @color2); } Then, in my main.less I'm trying something like this: a { .linear-gradient(top, #999, #666); } That works fine, by say I want to do something like this: a { .linear-gradient(top, , #666); } Now, the first color should default to its default mixin color. How do I do this? Is this even possible Less isn't quite that clever. You can either be explicit: .linear-gradient(top, #fff, #000); or use a variable as an abstraction to

Django Rest Framework - “detail”: “Not found.”

▼魔方 西西 提交于 2019-12-08 14:48:31
问题 Hi when doing this request: groups/25010a31-fc5b-47c8-9c5c-d740e5743f52/members/4/ - I get "detail": "Not found" However, if you look in the queryset I have printed the Groupmember instance and this ends up printing out that particular instance so clearly it exists? View: class MemberDetail(mixins.RetrieveModelMixin, mixins.DestroyModelMixin, mixins.UpdateModelMixin, generics.GenericAPIView): serializer_class = GroupMembersSerializer lookup_field = "user_id" lookup_url_kwarg = "uuid" def get

How to declare same style for @media and descendant selector?

*爱你&永不变心* 提交于 2019-12-08 11:59:01
问题 I need to define same style for elements under a media query and descendant by another class. Perfect solution in LESS could be the following [pseudo-code]: .foo { color:red; .example &, @media (min-width:800px) { color:blue; } } that should be desirable that would be compiled into: .foo { color: red; } .example .foo { color: blue; } @media (min-width: 800px) { .foo { color: blue; } } THIS SYNTAX IS INCORRECT but, do you have some suggestion to solve my problem? 回答1: Nope, selectors and

Imitate multiple inheritance with overriding

帅比萌擦擦* 提交于 2019-12-08 11:44:46
问题 Last time I found out how to force typescript to see methods copied to class prototype from the other place. The ways were about declaring fields: Fiddle class First { someMethod() { console.log('someMethod from First'); } } function Second() { console.log('Second'); } Second.prototype.doSmth = function () { console.log('doSmth from Second'); } class Both extends First { constructor() { console.log('constructor of Both'); super(); Second.call(this); } doSmth: () => void } for (let key in