Javascript ES 6类-混合
我提出了视图(HTML标记)和实用程序(JavaScript-行为)体系结构,并使用ES6类创建用于组合视图和实用程序的原子类。需要将多个实用程序类组合/混合到一个视图类中Javascript ES 6类-混合,javascript,ecmascript-6,mixins,traits,Javascript,Ecmascript 6,Mixins,Traits,我提出了视图(HTML标记)和实用程序(JavaScript-行为)体系结构,并使用ES6类创建用于组合视图和实用程序的原子类。需要将多个实用程序类组合/混合到一个视图类中 ES6类API如何提供一种将类中的内容混合到另一个/主类中的方法。我已经研究了对象。分配,但这是针对对象的,而不是在类级别。JavaScript类现在,希望将来也会如此 只能相互延伸,不能混合 彼此之间的关系。如果有的话,那么最有可能轻量级特征 有一天一定要把它做成规格 它的体系结构方法是特定于JavaScript的。信息技
ES6类API如何提供一种将类中的内容混合到另一个/主类中的方法。我已经研究了
对象。分配
,但这是针对对象的,而不是在类级别。JavaScript类现在,希望将来也会如此
只能相互延伸,不能混合
彼此之间的关系。如果有的话,那么最有可能轻量级特征
有一天一定要把它做成规格
它的体系结构方法是特定于JavaScript的。信息技术
在过去几年中经常被提及。。。
esdiscussion.org:,
github.com/WebReflection:,
webreflection.blogspot.com:,
reddit.com/r/javascript:,
raganwald.com:。。。
和安格斯·克罗尔的相比可能是最好的
基于纯函数的Mixin/Trait方法,
...
一定要接近OP的要求,除非有什么
类似于
// proposed trait syntax ... // ... desugared e.g. to ...
trait Enumerable_first_last { // var Enumerable_first_last = (function () {
// trait body. // // mixin module.
//
const // var
FIRST = function () { // first = function () { // shared code.
return this[0]; // return this[0];
}, // },
LAST = function () { // last = function () {
return this[this.length - 1]; // return this[this.length - 1];
} // }
; // ;
//
applicator () { // return function Enumerable_first_last () {
// applicator body. // // mixin body.
//
this.first = FIRST; // this.first = first; // referencing ...
this.last = LAST; // this.last = last; // ... shared code.
} // };
//
} // }());
。。。已被发送到ECMAScript领域。JavaScript类现在,希望将来也能 只能相互延伸,不能混合 彼此之间的关系。如果有的话,那么最有可能轻量级特征 有一天一定要把它做成规格 它的体系结构方法是特定于JavaScript的。信息技术 在过去几年中经常被提及。。。 esdiscussion.org:, github.com/WebReflection:, webreflection.blogspot.com:, reddit.com/r/javascript:, raganwald.com:。。。 和安格斯·克罗尔的相比可能是最好的 基于纯函数的Mixin/Trait方法, ... 一定要接近OP的要求,除非有什么 类似于
// proposed trait syntax ... // ... desugared e.g. to ...
trait Enumerable_first_last { // var Enumerable_first_last = (function () {
// trait body. // // mixin module.
//
const // var
FIRST = function () { // first = function () { // shared code.
return this[0]; // return this[0];
}, // },
LAST = function () { // last = function () {
return this[this.length - 1]; // return this[this.length - 1];
} // }
; // ;
//
applicator () { // return function Enumerable_first_last () {
// applicator body. // // mixin body.
//
this.first = FIRST; // this.first = first; // referencing ...
this.last = LAST; // this.last = last; // ... shared code.
} // };
//
} // }());
。。。已发布到ECMAScript land。ES2015类有一个非常好的模式(我不一定赞同这种模式)来创建mixin,我稍微调整了一下 实用程序函数
mixinClasses
可用于将类内工厂(也称为返回类的工厂函数)混合到新类中:
function mixinClasses(...mixins) {
// TODO: Add all possible method names that might call super()
// to the base class so that they don't throw.
return mixins.reduce((base, mixin) => {
return mixin(base);
}, class {});
}
可按如下方式使用,例如与两个出厂功能Foo
和Bar
:
const Foo = base => class extends base {
myFn() {
}
};
const Bar = base => class extends base {
myFn() {
super.myFn();
}
};
class Baz extends mixinClasses(Foo, Bar) {
myFn() {
super.myFn();
}
}
ES2015类有一个非常好的模式(我不一定赞同这样的模式)来创建混合,我稍微调整了一下 实用程序函数
mixinClasses
可用于将类内工厂(也称为返回类的工厂函数)混合到新类中:
function mixinClasses(...mixins) {
// TODO: Add all possible method names that might call super()
// to the base class so that they don't throw.
return mixins.reduce((base, mixin) => {
return mixin(base);
}, class {});
}
可按如下方式使用,例如与两个出厂功能Foo
和Bar
:
const Foo = base => class extends base {
myFn() {
}
};
const Bar = base => class extends base {
myFn() {
super.myFn();
}
};
class Baz extends mixinClasses(Foo, Bar) {
myFn() {
super.myFn();
}
}
1/2-为了证明上面的特征语法,我提供了一个库,并且示例性地重构了其他4个与特征相关的JavaScript Q的代码,分别是ara(1),(2),…2/2-(3)和(4)。1/2-为了证明上面的特征语法,我提供了一个库,并且示例性地重构了其他4个与特征相关的JavaScript Q的代码,其中ara(1)、(2)、(2/2-(3)和(4)。