本文整理汇总了TypeScript中glimmer-object.Mixin.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Mixin.create方法的具体用法?TypeScript Mixin.create怎么用?TypeScript Mixin.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glimmer-object.Mixin
的用法示例。
在下文中一共展示了Mixin.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
QUnit.test('Including the same mixin more than once will only run once', function() {
let cnt = 0;
let MixinA = Mixin.create({
foo() { cnt++; }
});
let MixinB = Mixin.create(MixinA, {
foo() { this._super.apply(this, arguments); }
});
let MixinC = Mixin.create(MixinA, {
foo() { this._super.apply(this, arguments); }
});
let MixinD = Mixin.create(MixinB, MixinC, MixinA, {
foo() { this._super.apply(this, arguments); }
});
let obj = {};
MixinD.apply(obj);
MixinA.apply(obj); // try to apply again..
cnt = 0;
obj['foo']();
equal(cnt, 1, 'should invoke MixinA.foo one time');
});
示例2: function
QUnit.test('mergedProperties\' overwriting methods can call _super', function() {
expect(4);
let MixinA = Mixin.create({
mergedProperties: ['foo'],
foo: {
meth(a) {
equal(a, 'WOOT', '_super successfully called MixinA\'s `foo.meth` method');
return 'WAT';
}
}
});
let MixinB = Mixin.create({
foo: {
meth(a) {
ok(true, 'MixinB\'s `foo.meth` method called');
return this._super.apply(this, arguments);
}
}
});
let MixinC = Mixin.create({
foo: {
meth(a) {
ok(true, 'MixinC\'s `foo.meth` method called');
return this._super(a);
}
}
});
let obj = mixin({}, MixinA, MixinB, MixinC);
equal(obj.foo.meth('WOOT'), 'WAT');
});
示例3: function
QUnit.test('detect() finds nested mixins', function() {
let MixinA = Mixin.create({});
let MixinB = Mixin.create(MixinA);
let obj = {};
equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');
MixinB.apply(obj);
equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
});
示例4: function
QUnit.test('defining concatenated properties should concat future version', function() {
let MixinA = Mixin.create({
concatenatedProperties: null
});
let MixinB = Mixin.create({
concatenatedProperties: null
});
let obj = mixin({}, MixinA, MixinB);
deepEqual(obj.concatenatedProperties, []);
});